Home | History | Annotate | Download | only in InstCombine
      1 ; This test makes sure that these instructions are properly eliminated.
      2 ;
      3 
      4 ; RUN: opt < %s -instcombine -S | not grep xor
      5 
      6 define i32 @test1(i32 %A) {
      7         %B = xor i32 %A, -1             ; <i32> [#uses=1]
      8         %C = xor i32 %B, -1             ; <i32> [#uses=1]
      9         ret i32 %C
     10 }
     11 
     12 define i1 @test2(i32 %A, i32 %B) {
     13         ; Can change into setge
     14         %cond = icmp sle i32 %A, %B             ; <i1> [#uses=1]
     15         %Ret = xor i1 %cond, true               ; <i1> [#uses=1]
     16         ret i1 %Ret
     17 }
     18 
     19 ; Test that demorgans law can be instcombined
     20 define i32 @test3(i32 %A, i32 %B) {
     21         %a = xor i32 %A, -1             ; <i32> [#uses=1]
     22         %b = xor i32 %B, -1             ; <i32> [#uses=1]
     23         %c = and i32 %a, %b             ; <i32> [#uses=1]
     24         %d = xor i32 %c, -1             ; <i32> [#uses=1]
     25         ret i32 %d
     26 }
     27 
     28 ; Test that demorgens law can work with constants
     29 define i32 @test4(i32 %A, i32 %B) {
     30         %a = xor i32 %A, -1             ; <i32> [#uses=1]
     31         %c = and i32 %a, 5              ; <i32> [#uses=1]
     32         %d = xor i32 %c, -1             ; <i32> [#uses=1]
     33         ret i32 %d
     34 }
     35 
     36 ; test the mirror of demorgans law...
     37 define i32 @test5(i32 %A, i32 %B) {
     38         %a = xor i32 %A, -1             ; <i32> [#uses=1]
     39         %b = xor i32 %B, -1             ; <i32> [#uses=1]
     40         %c = or i32 %a, %b              ; <i32> [#uses=1]
     41         %d = xor i32 %c, -1             ; <i32> [#uses=1]
     42         ret i32 %d
     43 }
     44 
     45 ; PR2298
     46 define zeroext i8 @test6(i32 %a, i32 %b)  nounwind  {
     47 entry:
     48 	%tmp1not = xor i32 %a, -1		; <i32> [#uses=1]
     49 	%tmp2not = xor i32 %b, -1		; <i32> [#uses=1]
     50 	%tmp3 = icmp slt i32 %tmp1not, %tmp2not		; <i1> [#uses=1]
     51 	%retval67 = zext i1 %tmp3 to i8		; <i8> [#uses=1]
     52 	ret i8 %retval67
     53 }
     54 
     55