[llvm] r287604 - Analysis: gep inbounds (gep inbounds (...)) is inbounds.
Peter Collingbourne via llvm-commits
llvm-commits at lists.llvm.org
Mon Nov 21 17:03:40 PST 2016
Author: pcc
Date: Mon Nov 21 19:03:40 2016
New Revision: 287604
URL: http://llvm.org/viewvc/llvm-project?rev=287604&view=rev
Log:
Analysis: gep inbounds (gep inbounds (...)) is inbounds.
Differential Revision: https://reviews.llvm.org/D26441
Modified:
llvm/trunk/lib/Analysis/ConstantFolding.cpp
llvm/trunk/test/Other/constant-fold-gep.ll
Modified: llvm/trunk/lib/Analysis/ConstantFolding.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ConstantFolding.cpp?rev=287604&r1=287603&r2=287604&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/ConstantFolding.cpp (original)
+++ llvm/trunk/lib/Analysis/ConstantFolding.cpp Mon Nov 21 19:03:40 2016
@@ -773,6 +773,7 @@ Constant *SymbolicallyEvaluateGEP(const
const DataLayout &DL,
const TargetLibraryInfo *TLI) {
const GEPOperator *InnermostGEP = GEP;
+ bool InBounds = GEP->isInBounds();
Type *SrcElemTy = GEP->getSourceElementType();
Type *ResElemTy = GEP->getResultElementType();
@@ -825,6 +826,7 @@ Constant *SymbolicallyEvaluateGEP(const
// If this is a GEP of a GEP, fold it all into a single GEP.
while (auto *GEP = dyn_cast<GEPOperator>(Ptr)) {
InnermostGEP = GEP;
+ InBounds &= GEP->isInBounds();
SmallVector<Value *, 4> NestedOps(GEP->op_begin() + 1, GEP->op_end());
@@ -946,8 +948,8 @@ Constant *SymbolicallyEvaluateGEP(const
}
// Create a GEP.
- Constant *C = ConstantExpr::getGetElementPtr(
- SrcElemTy, Ptr, NewIdxs, /*InBounds=*/false, InRangeIndex);
+ Constant *C = ConstantExpr::getGetElementPtr(SrcElemTy, Ptr, NewIdxs,
+ InBounds, InRangeIndex);
assert(C->getType()->getPointerElementType() == Ty &&
"Computed GetElementPtr has unexpected type!");
Modified: llvm/trunk/test/Other/constant-fold-gep.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Other/constant-fold-gep.ll?rev=287604&r1=287603&r2=287604&view=diff
==============================================================================
--- llvm/trunk/test/Other/constant-fold-gep.ll (original)
+++ llvm/trunk/test/Other/constant-fold-gep.ll Mon Nov 21 19:03:40 2016
@@ -106,9 +106,9 @@
; PLAIN: @Y = global [3 x { i32, i32 }]* getelementptr inbounds ([3 x { i32, i32 }], [3 x { i32, i32 }]* @ext, i64 2)
; PLAIN: @Z = global i32* getelementptr inbounds (i32, i32* getelementptr inbounds ([3 x { i32, i32 }], [3 x { i32, i32 }]* @ext, i64 0, i64 1, i32 0), i64 1)
-; OPT: @Y = local_unnamed_addr global [3 x { i32, i32 }]* getelementptr ([3 x { i32, i32 }], [3 x { i32, i32 }]* @ext, i64 2)
+; OPT: @Y = local_unnamed_addr global [3 x { i32, i32 }]* getelementptr inbounds ([3 x { i32, i32 }], [3 x { i32, i32 }]* @ext, i64 2)
; OPT: @Z = local_unnamed_addr global i32* getelementptr inbounds ([3 x { i32, i32 }], [3 x { i32, i32 }]* @ext, i64 0, i64 1, i32 1)
-; TO: @Y = local_unnamed_addr global [3 x { i32, i32 }]* getelementptr ([3 x { i32, i32 }], [3 x { i32, i32 }]* @ext, i64 2)
+; TO: @Y = local_unnamed_addr global [3 x { i32, i32 }]* getelementptr inbounds ([3 x { i32, i32 }], [3 x { i32, i32 }]* @ext, i64 2)
; TO: @Z = local_unnamed_addr global i32* getelementptr inbounds ([3 x { i32, i32 }], [3 x { i32, i32 }]* @ext, i64 0, i64 1, i32 1)
@ext = external global [3 x { i32, i32 }]
More information about the llvm-commits
mailing list