llvm.org GIT mirror llvm / 009e265
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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@151383 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 7 years ago
2 changed file(s) with 29 addition(s) and 5 deletion(s). Raw diff Collapse all Expand all
15211521
15221522 /// stripPointerAdjustments - This is like Value::stripPointerCasts, but also
15231523 /// removes inbounds gep operations, regardless of their indices.
1524 static Value *stripPointerAdjustmentsImpl(Value *V,
1525 SmallPtrSet &VisitedGEPs) {
1526 GEPOperator *GEP = dyn_cast(V);
1527 if (GEP == 0 || !GEP->isInBounds())
1528 return V;
1529
1530 // If we've already seen this GEP, we will end up infinitely looping. This
1531 // can happen in unreachable code.
1532 if (!VisitedGEPs.insert(GEP))
1533 return V;
1534
1535 return stripPointerAdjustmentsImpl(GEP->getOperand(0)->stripPointerCasts(),
1536 VisitedGEPs);
1537 }
1538
15241539 static Value *stripPointerAdjustments(Value *V) {
1525 if (GEPOperator *GEP = dyn_cast(V))
1526 if (GEP->isInBounds())
1527 return stripPointerAdjustments(GEP->getOperand(0)->stripPointerCasts());
1528 return V;
1529 }
1540 SmallPtrSet VisitedGEPs;
1541 return stripPointerAdjustmentsImpl(V, VisitedGEPs);
1542 }
1543
15301544
15311545 /// SimplifyICmpInst - Given operands for an ICmpInst, see if we can
15321546 /// fold the result. If not, this returns null.
462462 ; CHECK: alloca_compare
463463 ; CHECK: ret i1 false
464464 }
465
466 ; PR12075
467 define i1 @infinite_gep() {
468 ret i1 1
469
470 unreachableblock:
471 %X = getelementptr i32 *%X, i32 1
472 %Y = icmp eq i32* %X, null
473 ret i1 %Y
474 }