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