[llvm-commits] [llvm] r151383 - in /llvm/trunk: lib/Analysis/InstructionSimplify.cpp test/Transforms/InstSimplify/compare.ll
Chris Lattner
sabre at nondot.org
Fri Feb 24 11:01:58 PST 2012
Author: lattner
Date: Fri Feb 24 13:01:58 2012
New Revision: 151383
URL: http://llvm.org/viewvc/llvm-project?rev=151383&view=rev
Log:
fix PR12075, a regression in a recent transform I added. In unreachable code, gep chains can be infinite. Just like "stripPointerCasts", use a set to keep track of visited instructions so we don't recurse infinitely.
Modified:
llvm/trunk/lib/Analysis/InstructionSimplify.cpp
llvm/trunk/test/Transforms/InstSimplify/compare.ll
Modified: llvm/trunk/lib/Analysis/InstructionSimplify.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/InstructionSimplify.cpp?rev=151383&r1=151382&r2=151383&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/InstructionSimplify.cpp (original)
+++ llvm/trunk/lib/Analysis/InstructionSimplify.cpp Fri Feb 24 13:01:58 2012
@@ -1522,13 +1522,27 @@
/// stripPointerAdjustments - This is like Value::stripPointerCasts, but also
/// removes inbounds gep operations, regardless of their indices.
+static Value *stripPointerAdjustmentsImpl(Value *V,
+ SmallPtrSet<GEPOperator*, 8> &VisitedGEPs) {
+ GEPOperator *GEP = dyn_cast<GEPOperator>(V);
+ if (GEP == 0 || !GEP->isInBounds())
+ return V;
+
+ // If we've already seen this GEP, we will end up infinitely looping. This
+ // can happen in unreachable code.
+ if (!VisitedGEPs.insert(GEP))
+ return V;
+
+ return stripPointerAdjustmentsImpl(GEP->getOperand(0)->stripPointerCasts(),
+ VisitedGEPs);
+}
+
static Value *stripPointerAdjustments(Value *V) {
- if (GEPOperator *GEP = dyn_cast<GEPOperator>(V))
- if (GEP->isInBounds())
- return stripPointerAdjustments(GEP->getOperand(0)->stripPointerCasts());
- return V;
+ SmallPtrSet<GEPOperator*, 8> VisitedGEPs;
+ return stripPointerAdjustmentsImpl(V, VisitedGEPs);
}
+
/// SimplifyICmpInst - Given operands for an ICmpInst, see if we can
/// fold the result. If not, this returns null.
static Value *SimplifyICmpInst(unsigned Predicate, Value *LHS, Value *RHS,
Modified: llvm/trunk/test/Transforms/InstSimplify/compare.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstSimplify/compare.ll?rev=151383&r1=151382&r2=151383&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstSimplify/compare.ll (original)
+++ llvm/trunk/test/Transforms/InstSimplify/compare.ll Fri Feb 24 13:01:58 2012
@@ -463,3 +463,13 @@
; CHECK: alloca_compare
; CHECK: ret i1 false
}
+
+; PR12075
+define i1 @infinite_gep() {
+ ret i1 1
+
+unreachableblock:
+ %X = getelementptr i32 *%X, i32 1
+ %Y = icmp eq i32* %X, null
+ ret i1 %Y
+}
More information about the llvm-commits
mailing list