; This test makes sure that these instructions are properly eliminated.
;
-; RUN: llvm-as < %s | opt -instcombine | llvm-dis | \
-; RUN: grep -v {sub i32 %Cok, %Bok} | not grep sub
+; RUN: opt < %s -instcombine -S | \
+; RUN: grep -v {sub i32 %Cok, %Bok} | grep -v {sub i32 0, %Aok} | not grep sub
define i32 @test1(i32 %A) {
%B = sub i32 %A, %A ; <i32> [#uses=1]
ret i32 %Y
}
-define i32 @test17(i32 %A) {
- %B = sub i32 0, %A ; <i32> [#uses=1]
+; Can't fold subtract here because negation it might oveflow.
+; PR3142
+define i32 @test17(i32 %Aok) {
+ %B = sub i32 0, %Aok ; <i32> [#uses=1]
%C = sdiv i32 %B, 1234 ; <i32> [#uses=1]
ret i32 %C
}
%tmp.4 = icmp ne i32 %tmp.2, %g ; <i1> [#uses=1]
ret i1 %tmp.4
}
+
+; PR2298
+define i8 @test22(i32 %a, i32 %b) zeroext nounwind {
+ %tmp2 = sub i32 0, %a ; <i32> [#uses=1]
+ %tmp4 = sub i32 0, %b ; <i32> [#uses=1]
+ %tmp5 = icmp eq i32 %tmp2, %tmp4 ; <i1> [#uses=1]
+ %retval89 = zext i1 %tmp5 to i8 ; <i8> [#uses=1]
+ ret i8 %retval89
+}
+