1 ; This test makes sure that these instructions are properly eliminated.
3 ; RUN: opt < %s -instcombine -S | FileCheck %s
6 define i1 @test0(i32 %A) {
8 ; CHECK: %C = icmp slt i32 %A, 0
9 %B = xor i32 %A, -2147483648
10 %C = icmp sgt i32 %B, -1
14 define i1 @test1(i32 %A) {
15 ; CHECK-LABEL: @test1(
16 ; CHECK: %C = icmp slt i32 %A, 0
17 %B = xor i32 %A, 12345
18 %C = icmp slt i32 %B, 0
23 define i32 @test2(i32 %tmp1) {
24 ; CHECK-LABEL: @test2(
25 ; CHECK-NEXT: and i32 %tmp1, 32
26 ; CHECK-NEXT: or i32 %ovm, 8
28 %ovm = and i32 %tmp1, 32
29 %ov3 = add i32 %ovm, 145
30 %ov110 = xor i32 %ov3, 153
34 define i32 @test3(i32 %tmp1) {
35 ; CHECK-LABEL: @test3(
36 ; CHECK-NEXT: and i32 %tmp1, 32
37 ; CHECK-NEXT: or i32 %ovm, 8
39 %ovm = or i32 %tmp1, 145
40 %ov31 = and i32 %ovm, 177
41 %ov110 = xor i32 %ov31, 153
45 define i32 @test4(i32 %A, i32 %B) {
50 ; CHECK-LABEL: @test4(
51 ; CHECK: %1 = ashr i32 %A, %B
55 ; defect-2 in rdar://12329730
56 ; (X^C1) >> C2) ^ C3 -> (X>>C2) ^ ((C1>>C2)^C3)
57 ; where the "X" has more than one use
58 define i32 @test5(i32 %val1) {
60 %xor = xor i32 %val1, 1234
61 %shr = lshr i32 %xor, 8
62 %xor1 = xor i32 %shr, 1
63 %add = add i32 %xor1, %xor
65 ; CHECK-LABEL: @test5(
66 ; CHECK: lshr i32 %val1, 8
70 ; defect-1 in rdar://12329730
71 ; Simplify (X^Y) -> X or Y in the user's context if we know that
72 ; only bits from X or Y are demanded.
73 ; e.g. the "x ^ 1234" can be optimized into x in the context of "t >> 16".
74 ; Put in other word, t >> 16 -> x >> 16.
75 ; unsigned foo(unsigned x) { unsigned t = x ^ 1234; ; return (t >> 16) + t;}
76 define i32 @test6(i32 %x) {
77 %xor = xor i32 %x, 1234
78 %shr = lshr i32 %xor, 16
79 %add = add i32 %shr, %xor
81 ; CHECK-LABEL: @test6(
82 ; CHECK: lshr i32 %x, 16