]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/patches/patch-17-llvm-r222856-libapr-miscompile.diff
Merge ^/head r275623 through 275634.
[FreeBSD/FreeBSD.git] / contrib / llvm / patches / patch-17-llvm-r222856-libapr-miscompile.diff
1 Pull in r222856 from upstream llvm trunk (by David Majnemer):
2
3   Revert "Added inst combine transforms for single bit tests from Chris's note"
4
5   This reverts commit r210006, it miscompiled libapr which is used in who
6   knows how many projects.
7
8   A test has been added to ensure that we don't regress again.
9
10 This fixes a miscompilation in libapr, which caused problems in svnlite.
11
12 Introduced here: http://svnweb.freebsd.org/changeset/base/275160
13
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
22 -///
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,
32                                    Value *FalseVal,
33                                    InstCombiner::BuilderTy *Builder) {
34    const ICmpInst *IC = dyn_cast<ICmpInst>(SI.getCondition());
35 @@ -414,25 +406,6 @@ static Value *SimplifyWithOpReplaced(Value *V, Val
36      return nullptr;
37  
38    const APInt *C2;
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))
45 -      return FalseVal;
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))
52 -      return X;
53 -    // if ((X & C) == 0) X |= C becomes X |= C
54 -    if (match(TrueVal, m_Or(m_Specific(X), m_APInt(C2))) && C1 == C2)
55 -      return TrueVal;
56 -  }
57 -
58    bool OrOnTrueVal = false;
59    bool OrOnFalseVal = match(FalseVal, m_Or(m_Specific(TrueVal), m_Power2(C2)));
60    if (!OrOnFalseVal)
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
66    ret <2 x i32> %select
67  }
68  
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
75 -  %or = or i32 %x, 8
76 -  %or.x = select i1 %cmp, i32 %or, i32 %x
77 -  ret i32 %or.x
78 -}
79 -
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
88 -  ret i32 %x.xor
89 -}
90 -
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
99 -  ret i32 %xor.x
100 -}
101 -
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
110 -  ret i32 %x.and1
111 -}
112 -
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
120 -  ret i32 %and1.x
121 -}
122 -
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
130 -  ret i64 %y.xor
131 -}
132 -
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
140 -  ret i64 %y.and1
141 -}
142 -
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
150 -  ret i64 %xor.y
151 -}
152 -
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
160 -  ret i64 %and1.y
161 -}
162 -
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
169 -  %or = or i64 %y, 8
170 -  %or.y = select i1 %cmp, i64 %or, i64 %y
171 -  ret i64 %or.y
172 -}
173 -
174  define i32 @test65(i64 %x) {
175    %1 = and i64 %x, 16
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]]
180  }
181 +
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
187 +  ret i32 %and1.x
188 +; CHECK-LABEL: @test87(
189 +; CHECK: and i32 %x, -2
190 +}