llvm.org GIT mirror llvm / 1de17d5
Fix PR 3471, and some cleanups. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@64177 91177308-0d34-0410-b5e6-96231b3b80d8 Dale Johannesen 10 years ago
2 changed file(s) with 65 addition(s) and 17 deletion(s). Raw diff Collapse all Expand all
429429 if (!AddRec->isAffine()) return false;
430430
431431 // If Start contains an SCEVAddRecExpr from a different loop, other than an
432 // outer loop of the current loop, reject it. SCEV has no concept of operating
433 // on one loop at a time so don't confuse it with such expressions.
432 // outer loop of the current loop, reject it. SCEV has no concept of
433 // operating on one loop at a time so don't confuse it with such expressions.
434434 if (containsAddRecFromDifferentLoop(Start, L))
435435 return false;
436436
773773 // which need not be an immediate predecessor of this PHI. This way we
774774 // need only one copy of it even if it is referenced multiple times in
775775 // the PHI. We don't do this when the original expression is inside the
776 // loop because multiple copies sometimes do useful sinking of code in that
777 // case(?).
776 // loop because multiple copies sometimes do useful sinking of code in
777 // that case(?).
778778 Instruction *OldLoc = dyn_cast(OperandValToReplace);
779779 if (L->contains(OldLoc->getParent())) {
780 // If this is a critical edge, split the edge so that we do not insert the
781 // code on all predecessor/successor paths. We do this unless this is the
782 // canonical backedge for this loop, as this can make some inserted code
783 // be in an illegal position.
780 // If this is a critical edge, split the edge so that we do not insert
781 // the code on all predecessor/successor paths. We do this unless this
782 // is the canonical backedge for this loop, as this can make some
783 // inserted code be in an illegal position.
784784 BasicBlock *PHIPred = PN->getIncomingBlock(i);
785785 if (e != 1 && PHIPred->getTerminator()->getNumSuccessors() > 1 &&
786786 (PN->getParent() != L->getHeader() || !L->contains(PHIPred))) {
12231223 return true;
12241224 }
12251225
1226 /// RequiresTypeConversion - Returns true if converting Ty to NewTy is not
1226 /// RequiresTypeConversion - Returns true if converting Ty1 to Ty2 is not
12271227 /// a nop.
12281228 bool LoopStrengthReduce::RequiresTypeConversion(const Type *Ty1,
12291229 const Type *Ty2) {
12301230 if (Ty1 == Ty2)
12311231 return false;
1232 if (Ty1->canLosslesslyBitCastTo(Ty2))
1233 return false;
12321234 if (TLI && TLI->isTruncateFree(Ty1, Ty2))
12331235 return false;
1234 return (!Ty1->canLosslesslyBitCastTo(Ty2) &&
1235 !(isa(Ty2) &&
1236 Ty1->canLosslesslyBitCastTo(UIntPtrTy)) &&
1237 !(isa(Ty1) &&
1238 Ty2->canLosslesslyBitCastTo(UIntPtrTy)));
1236 if (isa(Ty2) && Ty1->canLosslesslyBitCastTo(UIntPtrTy))
1237 return false;
1238 if (isa(Ty1) && Ty2->canLosslesslyBitCastTo(UIntPtrTy))
1239 return false;
1240 return true;
12391241 }
12401242
12411243 /// CheckForIVReuse - Returns the multiple if the stride is the multiple
16601662 Rewriter.clear();
16611663
16621664 // If we are reusing the iv, then it must be multiplied by a constant
1663 // factor take advantage of addressing mode scale component.
1665 // factor to take advantage of the addressing mode scale component.
16641666 if (!isa(RewriteFactor) ||
16651667 !cast(RewriteFactor)->isZero()) {
16661668 // If we're reusing an IV with a nonzero base (currently this happens
16671669 // only when all reuses are outside the loop) subtract that base here.
16681670 // The base has been used to initialize the PHI node but we don't want
16691671 // it here.
1670 if (!ReuseIV.Base->isZero())
1671 RewriteExpr = SE->getMinusSCEV(RewriteExpr, ReuseIV.Base);
1672 if (!ReuseIV.Base->isZero()) {
1673 SCEVHandle typedBase = ReuseIV.Base;
1674 if (RewriteExpr->getType()->getPrimitiveSizeInBits() !=
1675 ReuseIV.Base->getType()->getPrimitiveSizeInBits()) {
1676 // It's possible the original IV is a larger type than the new IV,
1677 // in which case we have to truncate the Base. We checked in
1678 // RequiresTypeConversion that this is valid.
1679 assert (RewriteExpr->getType()->getPrimitiveSizeInBits() <
1680 ReuseIV.Base->getType()->getPrimitiveSizeInBits() &&
1681 "Unexpected lengthening conversion!");
1682 typedBase = SE->getTruncateExpr(ReuseIV.Base,
1683 RewriteExpr->getType());
1684 }
1685 RewriteExpr = SE->getMinusSCEV(RewriteExpr, typedBase);
1686 }
16721687
16731688 // Multiply old variable, with base removed, by new scale factor.
16741689 RewriteExpr = SE->getMulExpr(RewriteFactor,
0 ; RUN: llvm-as < %s | llc
1 ; This used to crash.
2 ; ModuleID = 'bugpoint-reduced-simplified.bc'
3 target datalayout ="e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128"
4 target triple = "x86_64-unknown-linux-gnu"
5
6 define void @parse_number(i8* nocapture %p) nounwind {
7 entry:
8 %shift.0 = select i1 false, i32 4, i32 2 ; [#uses=1]
9 br label %bb47
10
11 bb47: ; preds = %bb47, %entry
12 br i1 false, label %bb54, label %bb47
13
14 bb54: ; preds = %bb47
15 br i1 false, label %bb56, label %bb66
16
17 bb56: ; preds = %bb62, %bb54
18 %p_addr.0.pn.rec = phi i64 [ %p_addr.6.rec, %bb62 ], [ 0, %bb54 ] ; [#uses=2]
19 %ch.6.in.in = phi i8* [ %p_addr.6, %bb62 ], [ null, %bb54 ] ; [#uses=0]
20 %indvar202 = trunc i64 %p_addr.0.pn.rec to i32 ; [#uses=1]
21 %frac_bits.0 = mul i32 %indvar202, %shift.0 ; [#uses=1]
22 %p_addr.6.rec = add i64 %p_addr.0.pn.rec, 1 ; [#uses=2]
23 %p_addr.6 = getelementptr i8* null, i64 %p_addr.6.rec ; [#uses=1]
24 br i1 false, label %bb66, label %bb62
25
26 bb62: ; preds = %bb56
27 br label %bb56
28
29 bb66: ; preds = %bb56, %bb54
30 %frac_bits.1 = phi i32 [ 0, %bb54 ], [ %frac_bits.0, %bb56 ] ; [#uses=0]
31 unreachable
32 }