mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-12-14 11:32:34 +00:00
Back out the change in 64918 that used sign-extensions when promoting
trip counts that use signed comparisons. It's not obviously the best approach for preserving trip count information, and at any rate there isn't anything in the tree right now that makes use of that, so for now always using zero-extensions is preferable. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@65347 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
e9865945ad
commit
15cab2817b
@ -97,8 +97,7 @@ namespace {
|
||||
Value *IndVar,
|
||||
BasicBlock *ExitingBlock,
|
||||
BranchInst *BI,
|
||||
SCEVExpander &Rewriter,
|
||||
bool SignExtendTripCount);
|
||||
SCEVExpander &Rewriter);
|
||||
void RewriteLoopExitValues(Loop *L, SCEV *IterationCount);
|
||||
|
||||
void DeleteTriviallyDeadInstructions(SmallPtrSet<Instruction*, 16> &Insts);
|
||||
@ -237,8 +236,7 @@ void IndVarSimplify::LinearFunctionTestReplace(Loop *L,
|
||||
Value *IndVar,
|
||||
BasicBlock *ExitingBlock,
|
||||
BranchInst *BI,
|
||||
SCEVExpander &Rewriter,
|
||||
bool SignExtendTripCount) {
|
||||
SCEVExpander &Rewriter) {
|
||||
// If the exiting block is not the same as the backedge block, we must compare
|
||||
// against the preincremented value, otherwise we prefer to compare against
|
||||
// the post-incremented value.
|
||||
@ -256,18 +254,11 @@ void IndVarSimplify::LinearFunctionTestReplace(Loop *L,
|
||||
if ((isa<SCEVConstant>(N) && !N->isZero()) ||
|
||||
SE->isLoopGuardedByCond(L, ICmpInst::ICMP_NE, N, Zero)) {
|
||||
// No overflow. Cast the sum.
|
||||
if (SignExtendTripCount)
|
||||
IterationCount = SE->getTruncateOrSignExtend(N, IndVar->getType());
|
||||
else
|
||||
IterationCount = SE->getTruncateOrZeroExtend(N, IndVar->getType());
|
||||
IterationCount = SE->getTruncateOrZeroExtend(N, IndVar->getType());
|
||||
} else {
|
||||
// Potential overflow. Cast before doing the add.
|
||||
if (SignExtendTripCount)
|
||||
IterationCount = SE->getTruncateOrSignExtend(IterationCount,
|
||||
IndVar->getType());
|
||||
else
|
||||
IterationCount = SE->getTruncateOrZeroExtend(IterationCount,
|
||||
IndVar->getType());
|
||||
IterationCount = SE->getTruncateOrZeroExtend(IterationCount,
|
||||
IndVar->getType());
|
||||
IterationCount =
|
||||
SE->getAddExpr(IterationCount,
|
||||
SE->getIntegerSCEV(1, IndVar->getType()));
|
||||
@ -279,12 +270,8 @@ void IndVarSimplify::LinearFunctionTestReplace(Loop *L,
|
||||
CmpIndVar = L->getCanonicalInductionVariableIncrement();
|
||||
} else {
|
||||
// We have to use the preincremented value...
|
||||
if (SignExtendTripCount)
|
||||
IterationCount = SE->getTruncateOrSignExtend(IterationCount,
|
||||
IndVar->getType());
|
||||
else
|
||||
IterationCount = SE->getTruncateOrZeroExtend(IterationCount,
|
||||
IndVar->getType());
|
||||
IterationCount = SE->getTruncateOrZeroExtend(IterationCount,
|
||||
IndVar->getType());
|
||||
CmpIndVar = IndVar;
|
||||
}
|
||||
|
||||
@ -482,9 +469,8 @@ static const Type *getEffectiveIndvarType(const PHINode *Phi) {
|
||||
/// whether an induction variable in the same type that starts
|
||||
/// at 0 would undergo signed overflow.
|
||||
///
|
||||
/// In addition to setting the NoSignedWrap, NoUnsignedWrap, and
|
||||
/// SignExtendTripCount variables, return the PHI for this induction
|
||||
/// variable.
|
||||
/// In addition to setting the NoSignedWrap, and NoUnsignedWrap,
|
||||
/// variables, return the PHI for this induction variable.
|
||||
///
|
||||
/// TODO: This duplicates a fair amount of ScalarEvolution logic.
|
||||
/// Perhaps this can be merged with ScalarEvolution::getIterationCount
|
||||
@ -494,8 +480,7 @@ static const PHINode *TestOrigIVForWrap(const Loop *L,
|
||||
const BranchInst *BI,
|
||||
const Instruction *OrigCond,
|
||||
bool &NoSignedWrap,
|
||||
bool &NoUnsignedWrap,
|
||||
bool &SignExtendTripCount) {
|
||||
bool &NoUnsignedWrap) {
|
||||
// Verify that the loop is sane and find the exit condition.
|
||||
const ICmpInst *Cmp = dyn_cast<ICmpInst>(OrigCond);
|
||||
if (!Cmp) return 0;
|
||||
@ -610,10 +595,6 @@ static const PHINode *TestOrigIVForWrap(const Loop *L,
|
||||
// less than some value in the same type. As such, it will never wrap.
|
||||
if (isSigned && !InitialVal->getValue().isMaxSignedValue()) {
|
||||
NoSignedWrap = true;
|
||||
// If the original induction variable starts at zero or greater,
|
||||
// the trip count can be considered signed.
|
||||
if (InitialVal->getValue().isNonNegative())
|
||||
SignExtendTripCount = true;
|
||||
} else if (!isSigned && !InitialVal->getValue().isMaxValue())
|
||||
NoUnsignedWrap = true;
|
||||
return PN;
|
||||
@ -700,7 +681,6 @@ bool IndVarSimplify::runOnLoop(Loop *L, LPPassManager &LPM) {
|
||||
// using it. We can currently only handle loops with a single exit.
|
||||
bool NoSignedWrap = false;
|
||||
bool NoUnsignedWrap = false;
|
||||
bool SignExtendTripCount = false;
|
||||
const PHINode *OrigControllingPHI = 0;
|
||||
if (!isa<SCEVCouldNotCompute>(IterationCount) && ExitingBlock)
|
||||
// Can't rewrite non-branch yet.
|
||||
@ -709,16 +689,14 @@ bool IndVarSimplify::runOnLoop(Loop *L, LPPassManager &LPM) {
|
||||
// Determine if the OrigIV will ever undergo overflow.
|
||||
OrigControllingPHI =
|
||||
TestOrigIVForWrap(L, BI, OrigCond,
|
||||
NoSignedWrap, NoUnsignedWrap,
|
||||
SignExtendTripCount);
|
||||
NoSignedWrap, NoUnsignedWrap);
|
||||
|
||||
// We'll be replacing the original condition, so it'll be dead.
|
||||
DeadInsts.insert(OrigCond);
|
||||
}
|
||||
|
||||
LinearFunctionTestReplace(L, IterationCount, IndVar,
|
||||
ExitingBlock, BI, Rewriter,
|
||||
SignExtendTripCount);
|
||||
ExitingBlock, BI, Rewriter);
|
||||
}
|
||||
|
||||
// Now that we have a canonical induction variable, we can rewrite any
|
||||
|
@ -1,6 +1,5 @@
|
||||
; RUN: llvm-as < %s | opt -indvars | llvm-dis > %t
|
||||
; RUN: grep sext %t | count 2
|
||||
; RUN: grep { = sext i32 %n to i64} %t
|
||||
; RUN: grep sext %t | count 1
|
||||
; RUN: grep phi %t | count 1
|
||||
; RUN: grep {phi i64} %t
|
||||
|
||||
|
@ -1,7 +1,5 @@
|
||||
; RUN: llvm-as < %s | opt -indvars | llvm-dis > %t
|
||||
; RUN: grep sext %t | count 2
|
||||
; RUN: grep { = sext i16 %N to i64} %t
|
||||
; RUN: grep { = sext i32 %count to i64} %t
|
||||
; RUN: not grep sext %t
|
||||
|
||||
define i64 @test(i64* nocapture %first, i32 %count) nounwind readonly {
|
||||
entry:
|
||||
|
@ -1,7 +1,6 @@
|
||||
; RUN: llvm-as < %s | opt -indvars | llvm-dis > %t
|
||||
; RUN: grep { = sext i32 %n} %t
|
||||
; RUN: not grep sext %t
|
||||
; RUN: grep phi %t | count 1
|
||||
; RUN: not grep zext %t
|
||||
|
||||
define void @foo(i64* nocapture %x, i32 %n) nounwind {
|
||||
entry:
|
||||
|
Loading…
Reference in New Issue
Block a user