1 Pull in r222856 from upstream llvm trunk (by David Majnemer):
3 Revert "Added inst combine transforms for single bit tests from Chris's note"
5 This reverts commit r210006, it miscompiled libapr which is used in who
6 knows how many projects.
8 A test has been added to ensure that we don't regress again.
10 This fixes a miscompilation in libapr, which caused problems in svnlite.
12 Introduced here: http://svnweb.freebsd.org/changeset/base/275160
14 Index: lib/Transforms/InstCombine/InstCombineSelect.cpp
15 ===================================================================
16 --- lib/Transforms/InstCombine/InstCombineSelect.cpp
17 +++ lib/Transforms/InstCombine/InstCombineSelect.cpp
18 @@ -387,15 +387,7 @@ static Value *SimplifyWithOpReplaced(Value *V, Val
19 /// 1. The icmp predicate is inverted
20 /// 2. The select operands are reversed
21 /// 3. The magnitude of C2 and C1 are flipped
23 -/// This also tries to turn
24 -/// --- Single bit tests:
25 -/// if ((x & C) == 0) x |= C to x |= C
26 -/// if ((x & C) != 0) x ^= C to x &= ~C
27 -/// if ((x & C) == 0) x ^= C to x |= C
28 -/// if ((x & C) != 0) x &= ~C to x &= ~C
29 -/// if ((x & C) == 0) x &= ~C to nothing
30 -static Value *foldSelectICmpAndOr(SelectInst &SI, Value *TrueVal,
31 +static Value *foldSelectICmpAndOr(const SelectInst &SI, Value *TrueVal,
33 InstCombiner::BuilderTy *Builder) {
34 const ICmpInst *IC = dyn_cast<ICmpInst>(SI.getCondition());
35 @@ -414,25 +406,6 @@ static Value *SimplifyWithOpReplaced(Value *V, Val
39 - if (match(TrueVal, m_Specific(X))) {
40 - // if ((X & C) != 0) X ^= C becomes X &= ~C
41 - if (match(FalseVal, m_Xor(m_Specific(X), m_APInt(C2))) && C1 == C2)
42 - return Builder->CreateAnd(X, ~(*C1));
43 - // if ((X & C) != 0) X &= ~C becomes X &= ~C
44 - if (match(FalseVal, m_And(m_Specific(X), m_APInt(C2))) && *C1 == ~(*C2))
46 - } else if (match(FalseVal, m_Specific(X))) {
47 - // if ((X & C) == 0) X ^= C becomes X |= C
48 - if (match(TrueVal, m_Xor(m_Specific(X), m_APInt(C2))) && C1 == C2)
49 - return Builder->CreateOr(X, *C1);
50 - // if ((X & C) == 0) X &= ~C becomes nothing
51 - if (match(TrueVal, m_And(m_Specific(X), m_APInt(C2))) && *C1 == ~(*C2))
53 - // if ((X & C) == 0) X |= C becomes X |= C
54 - if (match(TrueVal, m_Or(m_Specific(X), m_APInt(C2))) && C1 == C2)
58 bool OrOnTrueVal = false;
59 bool OrOnFalseVal = match(FalseVal, m_Or(m_Specific(TrueVal), m_Power2(C2)));
61 Index: test/Transforms/InstCombine/select.ll
62 ===================================================================
63 --- test/Transforms/InstCombine/select.ll
64 +++ test/Transforms/InstCombine/select.ll
65 @@ -996,111 +996,6 @@ define <2 x i32> @select_icmp_eq_and_1_0_or_vector
69 -; CHECK-LABEL: @select_icmp_and_8_eq_0_or_8(
70 -; CHECK-NEXT: [[OR:%[a-z0-9]+]] = or i32 %x, 8
71 -; CHECK-NEXT: ret i32 [[OR]]
72 -define i32 @select_icmp_and_8_eq_0_or_8(i32 %x) {
73 - %and = and i32 %x, 8
74 - %cmp = icmp eq i32 %and, 0
76 - %or.x = select i1 %cmp, i32 %or, i32 %x
80 -; CHECK-LABEL: @select_icmp_and_8_ne_0_xor_8(
81 -; CHECK-NEXT: [[AND:%[a-z0-9]+]] = and i32 %x, -9
82 -; CHECK-NEXT: ret i32 [[AND]]
83 -define i32 @select_icmp_and_8_ne_0_xor_8(i32 %x) {
84 - %and = and i32 %x, 8
85 - %cmp = icmp eq i32 %and, 0
86 - %xor = xor i32 %x, 8
87 - %x.xor = select i1 %cmp, i32 %x, i32 %xor
91 -; CHECK-LABEL: @select_icmp_and_8_eq_0_xor_8(
92 -; CHECK-NEXT: [[OR:%[a-z0-9]+]] = or i32 %x, 8
93 -; CHECK-NEXT: ret i32 [[OR]]
94 -define i32 @select_icmp_and_8_eq_0_xor_8(i32 %x) {
95 - %and = and i32 %x, 8
96 - %cmp = icmp eq i32 %and, 0
97 - %xor = xor i32 %x, 8
98 - %xor.x = select i1 %cmp, i32 %xor, i32 %x
102 -; CHECK-LABEL: @select_icmp_and_8_ne_0_and_not_8(
103 -; CHECK-NEXT: [[AND:%[a-z0-9]+]] = and i32 %x, -9
104 -; CHECK-NEXT: ret i32 [[AND]]
105 -define i32 @select_icmp_and_8_ne_0_and_not_8(i32 %x) {
106 - %and = and i32 %x, 8
107 - %cmp = icmp eq i32 %and, 0
108 - %and1 = and i32 %x, -9
109 - %x.and1 = select i1 %cmp, i32 %x, i32 %and1
113 -; CHECK-LABEL: @select_icmp_and_8_eq_0_and_not_8(
114 -; CHECK-NEXT: ret i32 %x
115 -define i32 @select_icmp_and_8_eq_0_and_not_8(i32 %x) {
116 - %and = and i32 %x, 8
117 - %cmp = icmp eq i32 %and, 0
118 - %and1 = and i32 %x, -9
119 - %and1.x = select i1 %cmp, i32 %and1, i32 %x
123 -; CHECK-LABEL: @select_icmp_x_and_8_eq_0_y_xor_8(
124 -; CHECK: select i1 %cmp, i64 %y, i64 %xor
125 -define i64 @select_icmp_x_and_8_eq_0_y_xor_8(i32 %x, i64 %y) {
126 - %and = and i32 %x, 8
127 - %cmp = icmp eq i32 %and, 0
128 - %xor = xor i64 %y, 8
129 - %y.xor = select i1 %cmp, i64 %y, i64 %xor
133 -; CHECK-LABEL: @select_icmp_x_and_8_eq_0_y_and_not_8(
134 -; CHECK: select i1 %cmp, i64 %y, i64 %and1
135 -define i64 @select_icmp_x_and_8_eq_0_y_and_not_8(i32 %x, i64 %y) {
136 - %and = and i32 %x, 8
137 - %cmp = icmp eq i32 %and, 0
138 - %and1 = and i64 %y, -9
139 - %y.and1 = select i1 %cmp, i64 %y, i64 %and1
143 -; CHECK-LABEL: @select_icmp_x_and_8_ne_0_y_xor_8(
144 -; CHECK: select i1 %cmp, i64 %xor, i64 %y
145 -define i64 @select_icmp_x_and_8_ne_0_y_xor_8(i32 %x, i64 %y) {
146 - %and = and i32 %x, 8
147 - %cmp = icmp eq i32 %and, 0
148 - %xor = xor i64 %y, 8
149 - %xor.y = select i1 %cmp, i64 %xor, i64 %y
153 -; CHECK-LABEL: @select_icmp_x_and_8_ne_0_y_and_not_8(
154 -; CHECK: select i1 %cmp, i64 %and1, i64 %y
155 -define i64 @select_icmp_x_and_8_ne_0_y_and_not_8(i32 %x, i64 %y) {
156 - %and = and i32 %x, 8
157 - %cmp = icmp eq i32 %and, 0
158 - %and1 = and i64 %y, -9
159 - %and1.y = select i1 %cmp, i64 %and1, i64 %y
163 -; CHECK-LABEL: @select_icmp_x_and_8_ne_0_y_or_8(
164 -; CHECK: xor i64 %1, 8
165 -; CHECK: or i64 %2, %y
166 -define i64 @select_icmp_x_and_8_ne_0_y_or_8(i32 %x, i64 %y) {
167 - %and = and i32 %x, 8
168 - %cmp = icmp eq i32 %and, 0
170 - %or.y = select i1 %cmp, i64 %or, i64 %y
174 define i32 @test65(i64 %x) {
176 %2 = icmp ne i64 %1, 0
177 @@ -1236,3 +1131,13 @@ define i32 @test75(i32 %x) {
178 ; CHECK-NEXT: [[SEL:%[a-z0-9]+]] = select i1 [[CMP]], i32 68, i32 %x
179 ; CHECK-NEXT: ret i32 [[SEL]]
182 +define i32 @test87(i32 %x) {
183 + %and = and i32 %x, 1
184 + %cmp = icmp ne i32 %and, 0
185 + %and1 = and i32 %x, -2
186 + %and1.x = select i1 %cmp, i32 %and1, i32 %x
188 +; CHECK-LABEL: @test87(
189 +; CHECK: and i32 %x, -2