Skip to content

Commit 4858e08

Browse files
committed
[ConstraintElimination] Only strip casts preserving the representation.
Things like addrspacecast may not be no-ops, so we should not look through them.
1 parent 706c1dc commit 4858e08

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

llvm/lib/Transforms/Scalar/ConstraintElimination.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,8 @@ getConstraint(CmpInst::Predicate Pred, Value *Op0, Value *Op1,
166166
if (Pred != CmpInst::ICMP_ULE && Pred != CmpInst::ICMP_ULT)
167167
return {};
168168

169-
auto ADec = decompose(Op0->stripPointerCasts());
170-
auto BDec = decompose(Op1->stripPointerCasts());
169+
auto ADec = decompose(Op0->stripPointerCastsSameRepresentation());
170+
auto BDec = decompose(Op1->stripPointerCastsSameRepresentation());
171171
// Skip if decomposing either of the values failed.
172172
if (ADec.empty() || BDec.empty())
173173
return {};

llvm/test/Transforms/ConstraintElimination/pointercast.ll

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,19 +174,19 @@ define i1 @addrspacecast_and_cmp(i32* readonly %src, i32* readnone %min, i32* re
174174
; CHECK: checks:
175175
; CHECK-NEXT: [[C_3_MIN:%.*]] = icmp ult i32* [[GEP_3]], [[MIN]]
176176
; CHECK-NEXT: [[C_3_MAX:%.*]] = icmp ult i32* [[GEP_3]], [[MAX]]
177-
; CHECK-NEXT: [[RES_1:%.*]] = xor i1 false, [[C_3_MAX]]
177+
; CHECK-NEXT: [[RES_1:%.*]] = xor i1 [[C_3_MIN]], [[C_3_MAX]]
178178
; CHECK-NEXT: [[GEP_1:%.*]] = getelementptr inbounds i32, i32* [[SRC]], i64 1
179179
; CHECK-NEXT: [[C_1_MIN:%.*]] = icmp ult i32* [[GEP_1]], [[MIN]]
180180
; CHECK-NEXT: [[C_1_MAX:%.*]] = icmp ult i32* [[GEP_1]], [[MAX]]
181-
; CHECK-NEXT: [[RES_2:%.*]] = xor i1 false, true
181+
; CHECK-NEXT: [[RES_2:%.*]] = xor i1 [[C_1_MIN]], [[C_1_MAX]]
182182
; CHECK-NEXT: [[GEP_2:%.*]] = getelementptr inbounds i32, i32* [[SRC]], i64 2
183183
; CHECK-NEXT: [[C_2_MIN:%.*]] = icmp ult i32* [[GEP_2]], [[MIN]]
184184
; CHECK-NEXT: [[C_2_MAX:%.*]] = icmp ult i32* [[GEP_2]], [[MAX]]
185-
; CHECK-NEXT: [[RES_3:%.*]] = xor i1 false, true
185+
; CHECK-NEXT: [[RES_3:%.*]] = xor i1 [[C_2_MIN]], [[C_2_MAX]]
186186
; CHECK-NEXT: [[GEP_4:%.*]] = getelementptr inbounds i32, i32* [[SRC]], i64 4
187187
; CHECK-NEXT: [[C_4_MIN:%.*]] = icmp ult i32* [[GEP_4]], [[MIN]]
188188
; CHECK-NEXT: [[C_4_MAX:%.*]] = icmp ult i32* [[GEP_4]], [[MAX]]
189-
; CHECK-NEXT: [[RES_4:%.*]] = xor i1 false, [[C_4_MAX]]
189+
; CHECK-NEXT: [[RES_4:%.*]] = xor i1 [[C_4_MIN]], [[C_4_MAX]]
190190
; CHECK-NEXT: [[RES_5:%.*]] = xor i1 [[RES_1]], [[RES_2]]
191191
; CHECK-NEXT: [[RES_6:%.*]] = xor i1 [[RES_5]], [[RES_3]]
192192
; CHECK-NEXT: [[RES_7:%.*]] = xor i1 [[RES_6]], [[RES_4]]

0 commit comments

Comments
 (0)