Skip to content

Commit 269f0dd

Browse files
committed
[InstCombine] Lower multi-dimensional GEP to ptradd
1 parent d7c7562 commit 269f0dd

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
@@ -3017,6 +3017,15 @@ static bool shouldCanonicalizeGEPToPtrAdd(GetElementPtrInst &GEP) {
30173017
m_Shl(m_Value(), m_ConstantInt())))))
30183018
return true;
30193019

3020+
// Flatten multidimensional GEPs with one variable index.
3021+
unsigned NumVarIndices = 0;
3022+
for (unsigned i = 1; i < GEP.getNumOperands(); ++i) {
3023+
if (!isa<ConstantInt>(GEP.getOperand(i)))
3024+
++NumVarIndices;
3025+
}
3026+
if (NumVarIndices == 1)
3027+
return true;
3028+
30203029
// gep (gep %p, C1), %x, C2 is expanded so the two constants can
30213030
// possibly be merged together.
30223031
auto PtrOpGep = dyn_cast<GEPOperator>(PtrOp);

0 commit comments

Comments
 (0)