-
-
Save nikic/8a1a82382468c88f19094d4b0a2f547c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp | |
index 4fc6b4de976b..ca62e6504856 100644 | |
--- a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp | |
+++ b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp | |
@@ -2057,10 +2057,19 @@ Instruction *InstCombinerImpl::visitGEPOfGEP(GetElementPtrInst &GEP, | |
return nullptr; | |
// Convert the total offset back into indices. | |
+ APInt OrigOffset = Offset; | |
SmallVector<APInt> ConstIndices = | |
DL.getGEPIndicesForOffset(BaseType, Offset); | |
- if (!Offset.isZero() || (!IsFirstType && !ConstIndices[0].isZero())) | |
+ if (!Offset.isZero() || (!IsFirstType && !ConstIndices[0].isZero())) { | |
+ // When combining two constant GEPs, fall back to i8 element type. | |
+ if (Src->hasAllConstantIndices()) | |
+ return replaceInstUsesWith( | |
+ GEP, Builder.CreateGEP( | |
+ Builder.getInt8Ty(), Src->getPointerOperand(), | |
+ Builder.getInt(OrigOffset), "", | |
+ isMergedGEPInBounds(*Src, *cast<GEPOperator>(&GEP)))); | |
return nullptr; | |
+ } | |
SmallVector<Value *> Indices; | |
append_range(Indices, drop_end(Src->indices(), |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment