[IndVars] Quick fix LHS/RHS bug
authorMax Kazantsev <mkazantsev@azul.com>
Fri, 4 Dec 2020 04:57:39 +0000 (11:57 +0700)
committerMax Kazantsev <mkazantsev@azul.com>
Fri, 4 Dec 2020 05:34:42 +0000 (12:34 +0700)
The code relies on fact that LHS is the NarrowDef but never
really checks it. Adding the conservative restrictive check,
will follow-up with handling of case where RHS is a NarrowDef.

llvm/lib/Transforms/Utils/SimplifyIndVar.cpp

index d37fe74..8842dfe 100644 (file)
@@ -1595,6 +1595,9 @@ bool WidenIV::widenWithVariantUse(WidenIV::NarrowIVDefUse DU) {
       return false;
     const SCEV *LHS = SE->getSCEV(OBO->getOperand(0));
     const SCEV *RHS = SE->getSCEV(OBO->getOperand(1));
+    // TODO: Support case for NarrowDef = NarrowUse->getOperand(1).
+    if (NarrowUse->getOperand(0) != NarrowDef)
+      return false;
     if (!SE->isKnownNegative(RHS))
       return false;
     bool ProvedSubNUW = SE->isKnownPredicateAt(