Skip to content

Commit 7a4f1d5

Browse files
committed
[ConstraintElimination] Decompose GEP %ptr, ZEXT(SHL()).
Add support to decompose a GEP with a ZEXT(SHL()) operand.
1 parent 4431c21 commit 7a4f1d5

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

llvm/lib/Transforms/Scalar/ConstraintElimination.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ static SmallVector<std::pair<int64_t, Value *>, 4> decompose(Value *V) {
6464
return {{0, nullptr},
6565
{1, GEP->getPointerOperand()},
6666
{pow(2, CI->getSExtValue()), Op0}};
67+
if (match(GEP->getOperand(GEP->getNumOperands() - 1),
68+
m_ZExt(m_NUWShl(m_Value(Op0), m_ConstantInt(CI)))))
69+
return {{0, nullptr},
70+
{1, GEP->getPointerOperand()},
71+
{pow(2, CI->getSExtValue()), Op0}};
6772

6873
return {{0, nullptr},
6974
{1, GEP->getPointerOperand()},

llvm/test/Transforms/ConstraintElimination/geps.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ define void @test.ult.gep.shl.zext(i32* readonly %src, i32* readnone %max, i32 %
455455
; CHECK-NEXT: [[EXT_1:%.*]] = zext i32 [[IDX_SHL]] to i64
456456
; CHECK-NEXT: [[ADD_PTR_SHL:%.*]] = getelementptr inbounds i32, i32* [[SRC]], i64 [[EXT_1]]
457457
; CHECK-NEXT: [[C_MAX_0:%.*]] = icmp ult i32* [[ADD_PTR_SHL]], [[MAX]]
458-
; CHECK-NEXT: call void @use(i1 [[C_MAX_0]])
458+
; CHECK-NEXT: call void @use(i1 true)
459459
; CHECK-NEXT: [[IDX_SHL_NOT_NUW:%.*]] = shl i32 [[IDX]], 1
460460
; CHECK-NEXT: [[EXT_2:%.*]] = zext i32 [[IDX_SHL_NOT_NUW]] to i64
461461
; CHECK-NEXT: [[ADD_PTR_SHL_NOT_NUW:%.*]] = getelementptr inbounds i32, i32* [[SRC]], i64 [[EXT_2]]

0 commit comments

Comments
 (0)