Skip to content

Commit fbd143d

Browse files
committed
[InstCombine] Lower multi-dimensional GEP to ptradd
1 parent eb43b79 commit fbd143d

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

llvm/lib/Transforms/InstCombine/InstructionCombining.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2995,6 +2995,15 @@ static bool shouldCanonicalizeGEPToPtrAdd(GetElementPtrInst &GEP) {
29952995
m_Shl(m_Value(), m_ConstantInt())))))
29962996
return true;
29972997

2998+
// Flatten multidimensional GEPs with one variable index.
2999+
unsigned NumVarIndices = 0;
3000+
for (unsigned i = 1; i < GEP.getNumOperands(); ++i) {
3001+
if (!isa<ConstantInt>(GEP.getOperand(i)))
3002+
++NumVarIndices;
3003+
}
3004+
if (NumVarIndices == 1)
3005+
return true;
3006+
29983007
// gep (gep %p, C1), %x, C2 is expanded so the two constants can
29993008
// possibly be merged together.
30003009
auto PtrOpGep = dyn_cast<GEPOperator>(PtrOp);

0 commit comments

Comments
 (0)