From 2ed501d6567180be986159fad6e5fd6431e8268d Mon Sep 17 00:00:00 2001 From: Tim Shen Date: Fri, 6 Jul 2018 23:20:35 +0000 Subject: Revert "[SCEV] Strengthen StrengthenNoWrapFlags (reapply r334428)." This reverts commit r336140. Our tests shows that LSR assert fails with it. llvm-svn: 336473 --- llvm/lib/Analysis/ScalarEvolution.cpp | 27 +++++++-------------------- 1 file changed, 7 insertions(+), 20 deletions(-) (limited to 'llvm/lib') diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp index 6480c2c076d..38bac434236 100644 --- a/llvm/lib/Analysis/ScalarEvolution.cpp +++ b/llvm/lib/Analysis/ScalarEvolution.cpp @@ -2244,35 +2244,22 @@ StrengthenNoWrapFlags(ScalarEvolution *SE, SCEVTypes Type, SignOrUnsignWrap = ScalarEvolution::maskFlags(Flags, SignOrUnsignMask); - if (SignOrUnsignWrap != SignOrUnsignMask && - (Type == scAddExpr || Type == scMulExpr) && Ops.size() == 2 && - isa(Ops[0])) { - - auto Opcode = [&] { - switch (Type) { - case scAddExpr: - return Instruction::Add; - case scMulExpr: - return Instruction::Mul; - default: - llvm_unreachable("Unexpected SCEV op."); - } - }(); + if (SignOrUnsignWrap != SignOrUnsignMask && Type == scAddExpr && + Ops.size() == 2 && isa(Ops[0])) { - const APInt &C = cast(Ops[0])->getAPInt(); + // (A + C) --> (A + C) if the addition does not sign overflow + // (A + C) --> (A + C) if the addition does not unsign overflow - // (A C) --> (A C) if the op doesn't sign overflow. + const APInt &C = cast(Ops[0])->getAPInt(); if (!(SignOrUnsignWrap & SCEV::FlagNSW)) { auto NSWRegion = ConstantRange::makeGuaranteedNoWrapRegion( - Opcode, C, OBO::NoSignedWrap); + Instruction::Add, C, OBO::NoSignedWrap); if (NSWRegion.contains(SE->getSignedRange(Ops[1]))) Flags = ScalarEvolution::setFlags(Flags, SCEV::FlagNSW); } - - // (A C) --> (A C) if the op doesn't unsign overflow. if (!(SignOrUnsignWrap & SCEV::FlagNUW)) { auto NUWRegion = ConstantRange::makeGuaranteedNoWrapRegion( - Opcode, C, OBO::NoUnsignedWrap); + Instruction::Add, C, OBO::NoUnsignedWrap); if (NUWRegion.contains(SE->getUnsignedRange(Ops[1]))) Flags = ScalarEvolution::setFlags(Flags, SCEV::FlagNUW); } -- cgit v1.2.3