[llvm-branch-commits] [llvm] f8cece1 - [ValueTracking] Fix one s/dyn_cast/dyn_cast_or_null/
Author: Markus Lavin Date: 2021-01-13T13:39:53+01:00 New Revision: f8cece18630575dccd62ba6a12f21acf5fd38c26 URL: https://github.com/llvm/llvm-project/commit/f8cece18630575dccd62ba6a12f21acf5fd38c26 DIFF: https://github.com/llvm/llvm-project/commit/f8cece18630575dccd62ba6a12f21acf5fd38c26.diff LOG: [ValueTracking] Fix one s/dyn_cast/dyn_cast_or_null/ Handle if Constant::getAggregateElement() returns nullptr in canCreateUndefOrPoison(). Differential Revision: https://reviews.llvm.org/D94494 Added: Modified: llvm/lib/Analysis/ValueTracking.cpp llvm/unittests/Analysis/ValueTrackingTest.cpp Removed: diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp index 1c75c5fbd0db..b138caa05610 100644 --- a/llvm/lib/Analysis/ValueTracking.cpp +++ b/llvm/lib/Analysis/ValueTracking.cpp @@ -4737,7 +4737,7 @@ static bool canCreateUndefOrPoison(const Operator *Op, bool PoisonOnly) { ShiftAmounts.push_back(C); bool Safe = llvm::all_of(ShiftAmounts, [](Constant *C) { -auto *CI = dyn_cast(C); +auto *CI = dyn_cast_or_null(C); return CI && CI->getValue().ult(C->getType()->getIntegerBitWidth()); }); return !Safe; diff --git a/llvm/unittests/Analysis/ValueTrackingTest.cpp b/llvm/unittests/Analysis/ValueTrackingTest.cpp index d70fd6eb0ba2..4b3b33b42625 100644 --- a/llvm/unittests/Analysis/ValueTrackingTest.cpp +++ b/llvm/unittests/Analysis/ValueTrackingTest.cpp @@ -943,6 +943,7 @@ TEST_F(ValueTrackingTest, isGuaranteedNotToBeUndefOrPoison_assume) { TEST(ValueTracking, canCreatePoisonOrUndef) { std::string AsmHead = + "@s = external dso_local global i32, align 1\n" "declare i32 @g(i32)\n" "define void @f(i32 %x, i32 %y, float %fx, float %fy, i1 %cond, " "<4 x i32> %vx, <4 x i32> %vx2, %svx, i8* %p) {\n"; @@ -1001,7 +1002,11 @@ TEST(ValueTracking, canCreatePoisonOrUndef) { {{true, false}, "call i32 @g(i32 %x)"}, {{false, false}, "call noundef i32 @g(i32 %x)"}, {{true, false}, "fcmp nnan oeq float %fx, %fy"}, - {{false, false}, "fcmp oeq float %fx, %fy"}}; + {{false, false}, "fcmp oeq float %fx, %fy"}, + {{true, false}, + "ashr <4 x i32> %vx, select (i1 icmp sgt (i32 ptrtoint (i32* @s to " + "i32), i32 1), <4 x i32> zeroinitializer, <4 x i32> )"}}; std::string AssemblyStr = AsmHead; for (auto &Itm : Data) ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] 808fcfe - Revert "[DebugInfo] Improve dbg preservation in LSR."
Author: Markus Lavin Date: 2020-11-27T08:52:32+01:00 New Revision: 808fcfe5944755f08ae88722070302fcf9135e58 URL: https://github.com/llvm/llvm-project/commit/808fcfe5944755f08ae88722070302fcf9135e58 DIFF: https://github.com/llvm/llvm-project/commit/808fcfe5944755f08ae88722070302fcf9135e58.diff LOG: Revert "[DebugInfo] Improve dbg preservation in LSR." This reverts commit 06758c6a6135f59deec8e73d4fcb69946ab47f54. Bug: https://bugs.llvm.org/show_bug.cgi?id=48166 Additional discussion in: https://reviews.llvm.org/D91711 Added: Modified: llvm/include/llvm/Analysis/ScalarEvolution.h llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp llvm/test/DebugInfo/COFF/fpo-shrink-wrap.ll Removed: llvm/test/Transforms/LoopStrengthReduce/dbg-preserve-0.ll diff --git a/llvm/include/llvm/Analysis/ScalarEvolution.h b/llvm/include/llvm/Analysis/ScalarEvolution.h index a7a24f086fbe..35e569710cab 100644 --- a/llvm/include/llvm/Analysis/ScalarEvolution.h +++ b/llvm/include/llvm/Analysis/ScalarEvolution.h @@ -1163,15 +1163,6 @@ class ScalarEvolution { const SCEV *S, const Loop *L, SmallPtrSetImpl &Preds); - /// Compute \p LHS - \p RHS and returns the result as an APInt if it is a - /// constant, and None if it isn't. - /// - /// This is intended to be a cheaper version of getMinusSCEV. We can be - /// frugal here since we just bail out of actually constructing and - /// canonicalizing an expression in the cases where the result isn't going - /// to be a constant. - Optional computeConstantDifference(const SCEV *LHS, const SCEV *RHS); - /// Update no-wrap flags of an AddRec. This may drop the cached info about /// this AddRec (such as range info) in case if new flags may potentially /// sharpen it. @@ -1893,6 +1884,15 @@ class ScalarEvolution { bool splitBinaryAdd(const SCEV *Expr, const SCEV *&L, const SCEV *&R, SCEV::NoWrapFlags &Flags); + /// Compute \p LHS - \p RHS and returns the result as an APInt if it is a + /// constant, and None if it isn't. + /// + /// This is intended to be a cheaper version of getMinusSCEV. We can be + /// frugal here since we just bail out of actually constructing and + /// canonicalizing an expression in the cases where the result isn't going + /// to be a constant. + Optional computeConstantDifference(const SCEV *LHS, const SCEV *RHS); + /// Drop memoized information computed for S. void forgetMemoizedResults(const SCEV *S); diff --git a/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp b/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp index 2713fa61ba31..a1d182931d0f 100644 --- a/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp +++ b/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp @@ -59,7 +59,6 @@ #include "llvm/ADT/Hashing.h" #include "llvm/ADT/PointerIntPair.h" #include "llvm/ADT/STLExtras.h" -#include "llvm/ADT/SetOperations.h" #include "llvm/ADT/SetVector.h" #include "llvm/ADT/SmallBitVector.h" #include "llvm/ADT/SmallPtrSet.h" @@ -81,7 +80,6 @@ #include "llvm/IR/BasicBlock.h" #include "llvm/IR/Constant.h" #include "llvm/IR/Constants.h" -#include "llvm/IR/DebugInfoMetadata.h" #include "llvm/IR/DerivedTypes.h" #include "llvm/IR/Dominators.h" #include "llvm/IR/GlobalValue.h" @@ -5788,27 +5786,6 @@ static bool ReduceLoopStrength(Loop *L, IVUsers &IU, ScalarEvolution &SE, if (MSSA) MSSAU = std::make_unique(MSSA); - // Debug preservation - record all llvm.dbg.value from the loop as well as - // the SCEV of their variable location. Since salvageDebugInfo may change the - // DIExpression we need to store the original here as well (i.e. it needs to - // be in sync with the SCEV). - SmallVector< - std::tuple, - 32> - DbgValues; - for (auto &B : L->getBlocks()) { -for (auto &I : *B) { - if (DbgValueInst *D = dyn_cast(&I)) { -auto V = D->getVariableLocation(); -if (!V || !SE.isSCEVable(V->getType())) - continue; -auto DS = SE.getSCEV(V); -DbgValues.push_back( -std::make_tuple(D, V->getType(), DS, D->getExpression())); - } -} - } - // Run the main LSR transformation. Changed |= LSRInstance(L, IU, SE, DT, LI, TTI, AC, TLI, MSSAU.get()).getChanged(); @@ -5830,40 +5807,6 @@ static bool ReduceLoopStrength(Loop *L, IVUsers &IU, ScalarEvolution &SE, DeleteDeadPHIs(L->getHeader(), &TLI, MSSAU.get()); } } - // Debug preservation - go through all recorded llvm.dbg.value and for those - // that now have an undef variable location use the recorded SCEV to try and - // update it. Compare with SCEV of Phi-nodes of loop header to find a - // suitable update candidate. SCEV match with constant offset is allowed and - // will be compensated for in the DIExpression. - if (Changed) { -for (auto &D : DbgValues) { - auto DbgValue = std::get(D); - auto DbgValueType
[llvm-branch-commits] [llvm] 2a6782b - Reland [DebugInfo] Improve dbg preservation in LSR.
Author: Markus Lavin Date: 2020-12-14T16:15:18+01:00 New Revision: 2a6782bb9f1d6843ab6e147765c1cdd7ee5eb90a URL: https://github.com/llvm/llvm-project/commit/2a6782bb9f1d6843ab6e147765c1cdd7ee5eb90a DIFF: https://github.com/llvm/llvm-project/commit/2a6782bb9f1d6843ab6e147765c1cdd7ee5eb90a.diff LOG: Reland [DebugInfo] Improve dbg preservation in LSR. Use SCEV to salvage additional @llvm.dbg.value that have turned into referencing undef after transformation (and traditional salvageDebugInfo). Before rewrite (but after introduction of new induction variables) use SCEV to compute an equivalent set of values for each @llvm.dbg.value in the loop body (among the loop header PHI-nodes). After rewrite (and dead PHI elimination) update those @llvm.dbg.value now referencing undef by picking a remaining value from its equivalence set. Allow match with offset by inserting compensation code in the DIExpression. Fixes : PR38815 Differential Revision: https://reviews.llvm.org/D87494 Added: llvm/test/Transforms/LoopStrengthReduce/dbg-preserve-0.ll Modified: llvm/include/llvm/Analysis/ScalarEvolution.h llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp llvm/test/DebugInfo/COFF/fpo-shrink-wrap.ll Removed: diff --git a/llvm/include/llvm/Analysis/ScalarEvolution.h b/llvm/include/llvm/Analysis/ScalarEvolution.h index 35e569710cab..a7a24f086fbe 100644 --- a/llvm/include/llvm/Analysis/ScalarEvolution.h +++ b/llvm/include/llvm/Analysis/ScalarEvolution.h @@ -1163,6 +1163,15 @@ class ScalarEvolution { const SCEV *S, const Loop *L, SmallPtrSetImpl &Preds); + /// Compute \p LHS - \p RHS and returns the result as an APInt if it is a + /// constant, and None if it isn't. + /// + /// This is intended to be a cheaper version of getMinusSCEV. We can be + /// frugal here since we just bail out of actually constructing and + /// canonicalizing an expression in the cases where the result isn't going + /// to be a constant. + Optional computeConstantDifference(const SCEV *LHS, const SCEV *RHS); + /// Update no-wrap flags of an AddRec. This may drop the cached info about /// this AddRec (such as range info) in case if new flags may potentially /// sharpen it. @@ -1884,15 +1893,6 @@ class ScalarEvolution { bool splitBinaryAdd(const SCEV *Expr, const SCEV *&L, const SCEV *&R, SCEV::NoWrapFlags &Flags); - /// Compute \p LHS - \p RHS and returns the result as an APInt if it is a - /// constant, and None if it isn't. - /// - /// This is intended to be a cheaper version of getMinusSCEV. We can be - /// frugal here since we just bail out of actually constructing and - /// canonicalizing an expression in the cases where the result isn't going - /// to be a constant. - Optional computeConstantDifference(const SCEV *LHS, const SCEV *RHS); - /// Drop memoized information computed for S. void forgetMemoizedResults(const SCEV *S); diff --git a/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp b/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp index ddd8856e92c5..0f82e196602f 100644 --- a/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp +++ b/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp @@ -81,6 +81,7 @@ #include "llvm/IR/BasicBlock.h" #include "llvm/IR/Constant.h" #include "llvm/IR/Constants.h" +#include "llvm/IR/DebugInfoMetadata.h" #include "llvm/IR/DerivedTypes.h" #include "llvm/IR/Dominators.h" #include "llvm/IR/GlobalValue.h" @@ -5774,6 +5775,62 @@ void LoopStrengthReduce::getAnalysisUsage(AnalysisUsage &AU) const { AU.addPreserved(); } +using EqualValues = SmallVector, 4>; +using EqualValuesMap = DenseMap; + +static void DbgGatherEqualValues(Loop *L, ScalarEvolution &SE, + EqualValuesMap &DbgValueToEqualSet) { + for (auto &B : L->getBlocks()) { +for (auto &I : *B) { + auto DVI = dyn_cast(&I); + if (!DVI) +continue; + auto V = DVI->getVariableLocation(); + if (!V || !SE.isSCEVable(V->getType())) +continue; + auto DbgValueSCEV = SE.getSCEV(V); + EqualValues EqSet; + for (PHINode &Phi : L->getHeader()->phis()) { +if (V->getType() != Phi.getType()) + continue; +if (!SE.isSCEVable(Phi.getType())) + continue; +auto PhiSCEV = SE.getSCEV(&Phi); +if (Optional Offset = +SE.computeConstantDifference(DbgValueSCEV, PhiSCEV)) + EqSet.emplace_back(std::make_tuple( + &Phi, Offset.getValue().getSExtValue(), DVI->getExpression())); + } + DbgValueToEqualSet[DVI] = std::move(EqSet); +} + } +} + +static void DbgApplyEqualValues(EqualValuesMap &DbgValueToEqualSet) { + for (auto A : DbgValueToEqualSet) { +auto DVI = A.first; +// Only update those that are now undef. +if (!isa_and_nonnull(DVI->getVariableLocation())) + continue; +for (auto EV : A.