1 ; Test that pure functions are cse'd away 2 ; RUN: opt < %s -globalsmodref-aa -gvn -instcombine | \ 3 ; RUN: llvm-dis | not grep sub 4 5 define i32 @pure(i32 %X) { 6 %Y = add i32 %X, 1 ; <i32> [#uses=1] 7 ret i32 %Y 8 } 9 10 define i32 @test1(i32 %X) { 11 %A = call i32 @pure( i32 %X ) ; <i32> [#uses=1] 12 %B = call i32 @pure( i32 %X ) ; <i32> [#uses=1] 13 %C = sub i32 %A, %B ; <i32> [#uses=1] 14 ret i32 %C 15 } 16 17 define i32 @test2(i32 %X, i32* %P) { 18 %A = call i32 @pure( i32 %X ) ; <i32> [#uses=1] 19 store i32 %X, i32* %P ;; Does not invalidate 'pure' call. 20 %B = call i32 @pure( i32 %X ) ; <i32> [#uses=1] 21 %C = sub i32 %A, %B ; <i32> [#uses=1] 22 ret i32 %C 23 } 24