1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -instcombine -S | FileCheck %s
4 ; https://bugs.llvm.org/show_bug.cgi?id=38446
8 ; Should be transformed into:
13 ; While -reassociate does handle this simple pattern, it does not handle
14 ; the more complicated motivating pattern.
16 ; ============================================================================ ;
17 ; Basic positive tests
18 ; ============================================================================ ;
20 ; If the operand is easily-invertible, fold into it.
23 define i1 @positive_easyinvert(i16 %x, i8 %y) {
24 ; CHECK-LABEL: @positive_easyinvert(
25 ; CHECK-NEXT: [[TMP1:%.*]] = icmp slt i16 [[X:%.*]], 0
26 ; CHECK-NEXT: [[TMP2:%.*]] = icmp sgt i8 [[Y:%.*]], -1
27 ; CHECK-NEXT: [[TMP4:%.*]] = xor i1 [[TMP2]], [[TMP1]]
28 ; CHECK-NEXT: ret i1 [[TMP4]]
30 %tmp1 = icmp slt i16 %x, 0
31 %tmp2 = icmp slt i8 %y, 0
32 %tmp3 = xor i1 %tmp2, %tmp1
33 %tmp4 = xor i1 %tmp3, true
37 define i1 @positive_easyinvert0(i8 %y) {
38 ; CHECK-LABEL: @positive_easyinvert0(
39 ; CHECK-NEXT: [[TMP1:%.*]] = call i1 @gen1()
40 ; CHECK-NEXT: [[TMP2:%.*]] = icmp sgt i8 [[Y:%.*]], -1
41 ; CHECK-NEXT: [[TMP4:%.*]] = xor i1 [[TMP2]], [[TMP1]]
42 ; CHECK-NEXT: ret i1 [[TMP4]]
44 %tmp1 = call i1 @gen1()
45 %tmp2 = icmp slt i8 %y, 0
46 %tmp3 = xor i1 %tmp2, %tmp1
47 %tmp4 = xor i1 %tmp3, true
51 define i1 @positive_easyinvert1(i8 %y) {
52 ; CHECK-LABEL: @positive_easyinvert1(
53 ; CHECK-NEXT: [[TMP1:%.*]] = call i1 @gen1()
54 ; CHECK-NEXT: [[TMP2:%.*]] = icmp sgt i8 [[Y:%.*]], -1
55 ; CHECK-NEXT: [[TMP4:%.*]] = xor i1 [[TMP2]], [[TMP1]]
56 ; CHECK-NEXT: ret i1 [[TMP4]]
58 %tmp1 = call i1 @gen1()
59 %tmp2 = icmp slt i8 %y, 0
60 %tmp3 = xor i1 %tmp1, %tmp2
61 %tmp4 = xor i1 %tmp3, true
65 ; ============================================================================ ;
66 ; One-use tests with easily-invertible operand.
67 ; ============================================================================ ;
69 declare void @use1(i1)
71 define i1 @oneuse_easyinvert_0(i8 %y) {
72 ; CHECK-LABEL: @oneuse_easyinvert_0(
73 ; CHECK-NEXT: [[TMP1:%.*]] = call i1 @gen1()
74 ; CHECK-NEXT: [[TMP2:%.*]] = icmp slt i8 [[Y:%.*]], 0
75 ; CHECK-NEXT: call void @use1(i1 [[TMP2]])
76 ; CHECK-NEXT: [[TMP3:%.*]] = xor i1 [[TMP1]], [[TMP2]]
77 ; CHECK-NEXT: [[TMP4:%.*]] = xor i1 [[TMP3]], true
78 ; CHECK-NEXT: ret i1 [[TMP4]]
80 %tmp1 = call i1 @gen1()
81 %tmp2 = icmp slt i8 %y, 0
82 call void @use1(i1 %tmp2)
83 %tmp3 = xor i1 %tmp1, %tmp2
84 %tmp4 = xor i1 %tmp3, true
88 define i1 @oneuse_easyinvert_1(i8 %y) {
89 ; CHECK-LABEL: @oneuse_easyinvert_1(
90 ; CHECK-NEXT: [[TMP1:%.*]] = call i1 @gen1()
91 ; CHECK-NEXT: [[TMP2:%.*]] = icmp slt i8 [[Y:%.*]], 0
92 ; CHECK-NEXT: [[TMP3:%.*]] = xor i1 [[TMP1]], [[TMP2]]
93 ; CHECK-NEXT: call void @use1(i1 [[TMP3]])
94 ; CHECK-NEXT: [[TMP4:%.*]] = xor i1 [[TMP3]], true
95 ; CHECK-NEXT: ret i1 [[TMP4]]
97 %tmp1 = call i1 @gen1()
98 %tmp2 = icmp slt i8 %y, 0
99 %tmp3 = xor i1 %tmp1, %tmp2
100 call void @use1(i1 %tmp3)
101 %tmp4 = xor i1 %tmp3, true
105 define i1 @oneuse_easyinvert_2(i8 %y) {
106 ; CHECK-LABEL: @oneuse_easyinvert_2(
107 ; CHECK-NEXT: [[TMP1:%.*]] = call i1 @gen1()
108 ; CHECK-NEXT: [[TMP2:%.*]] = icmp slt i8 [[Y:%.*]], 0
109 ; CHECK-NEXT: call void @use1(i1 [[TMP2]])
110 ; CHECK-NEXT: [[TMP3:%.*]] = xor i1 [[TMP1]], [[TMP2]]
111 ; CHECK-NEXT: call void @use1(i1 [[TMP3]])
112 ; CHECK-NEXT: [[TMP4:%.*]] = xor i1 [[TMP3]], true
113 ; CHECK-NEXT: ret i1 [[TMP4]]
115 %tmp1 = call i1 @gen1()
116 %tmp2 = icmp slt i8 %y, 0
117 call void @use1(i1 %tmp2)
118 %tmp3 = xor i1 %tmp1, %tmp2
119 call void @use1(i1 %tmp3)
120 %tmp4 = xor i1 %tmp3, true
124 ; ============================================================================ ;
126 ; ============================================================================ ;
128 ; Not easily invertible.
129 define i32 @negative(i32 %x, i32 %y) {
130 ; CHECK-LABEL: @negative(
131 ; CHECK-NEXT: [[TMP1:%.*]] = xor i32 [[X:%.*]], [[Y:%.*]]
132 ; CHECK-NEXT: [[TMP2:%.*]] = xor i32 [[TMP1]], -1
133 ; CHECK-NEXT: ret i32 [[TMP2]]
135 %tmp1 = xor i32 %x, %y
136 %tmp2 = xor i32 %tmp1, -1