[llvm] 3fe6ddd - [ConstraintElimination] Update Changed status in ssub simplification.

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Sun Oct 2 06:26:27 PDT 2022


Author: Florian Hahn
Date: 2022-10-02T14:25:51+01:00
New Revision: 3fe6ddd99976b02a3f703007f4e024213fced67e

URL: https://github.com/llvm/llvm-project/commit/3fe6ddd99976b02a3f703007f4e024213fced67e
DIFF: https://github.com/llvm/llvm-project/commit/3fe6ddd99976b02a3f703007f4e024213fced67e.diff

LOG: [ConstraintElimination] Update Changed status in ssub simplification.

Update tryToSimplifyOverflowMath to indicate whether the function made
any changes to the IR.

Added: 
    

Modified: 
    llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
    llvm/test/Transforms/ConstraintElimination/analysis-invalidation.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp b/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
index bc51c3b90b798..b881722a53025 100644
--- a/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
+++ b/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
@@ -670,7 +670,7 @@ void ConstraintInfo::addFact(CmpInst::Predicate Pred, Value *A, Value *B,
   }
 }
 
-static void
+static bool
 tryToSimplifyOverflowMath(IntrinsicInst *II, ConstraintInfo &Info,
                           SmallVectorImpl<Instruction *> &ToRemove) {
   auto DoesConditionHold = [](CmpInst::Predicate Pred, Value *A, Value *B,
@@ -684,6 +684,7 @@ tryToSimplifyOverflowMath(IntrinsicInst *II, ConstraintInfo &Info,
     return CSToUse.isConditionImplied(R.Coefficients);
   };
 
+  bool Changed = false;
   if (II->getIntrinsicID() == Intrinsic::ssub_with_overflow) {
     // If A s>= B && B s>= 0, ssub.with.overflow(a, b) should not overflow and
     // can be simplified to a regular sub.
@@ -692,7 +693,7 @@ tryToSimplifyOverflowMath(IntrinsicInst *II, ConstraintInfo &Info,
     if (!DoesConditionHold(CmpInst::ICMP_SGE, A, B, Info) ||
         !DoesConditionHold(CmpInst::ICMP_SGE, B,
                            ConstantInt::get(A->getType(), 0), Info))
-      return;
+      return false;
 
     IRBuilder<> Builder(II->getParent(), II->getIterator());
     Value *Sub = nullptr;
@@ -701,21 +702,27 @@ tryToSimplifyOverflowMath(IntrinsicInst *II, ConstraintInfo &Info,
         if (!Sub)
           Sub = Builder.CreateSub(A, B);
         U->replaceAllUsesWith(Sub);
-      } else if (match(U, m_ExtractValue<1>(m_Value())))
+        Changed = true;
+      } else if (match(U, m_ExtractValue<1>(m_Value()))) {
         U->replaceAllUsesWith(Builder.getFalse());
-      else
+        Changed = true;
+      } else
         continue;
 
       if (U->use_empty()) {
         auto *I = cast<Instruction>(U);
         ToRemove.push_back(I);
         I->setOperand(0, PoisonValue::get(II->getType()));
+        Changed = true;
       }
     }
 
-    if (II->use_empty())
+    if (II->use_empty()) {
       II->eraseFromParent();
+      Changed = true;
+    }
   }
+  return Changed;
 }
 
 static bool eliminateConstraints(Function &F, DominatorTree &DT) {
@@ -786,7 +793,7 @@ static bool eliminateConstraints(Function &F, DominatorTree &DT) {
     if (CB.IsBlock) {
       for (Instruction &I : make_early_inc_range(*CB.BB)) {
         if (auto *II = dyn_cast<WithOverflowInst>(&I)) {
-          tryToSimplifyOverflowMath(II, Info, ToRemove);
+          Changed |= tryToSimplifyOverflowMath(II, Info, ToRemove);
           continue;
         }
         auto *Cmp = dyn_cast<ICmpInst>(&I);

diff  --git a/llvm/test/Transforms/ConstraintElimination/analysis-invalidation.ll b/llvm/test/Transforms/ConstraintElimination/analysis-invalidation.ll
index 211635d96c490..66f3e19b036a1 100644
--- a/llvm/test/Transforms/ConstraintElimination/analysis-invalidation.ll
+++ b/llvm/test/Transforms/ConstraintElimination/analysis-invalidation.ll
@@ -11,7 +11,9 @@
 ; CHECK-NEXT: Running analysis: TargetIRAnalysis on ssub_no_overflow_due_to_or_conds
 ; CHECK-NEXT: Running analysis: DominatorTreeAnalysis on ssub_no_overflow_due_to_or_conds
 ; CHECK-NEXT: Running pass: ConstraintEliminationPass on ssub_no_overflow_due_to_or_conds
+; CHECK-NEXT: Invalidating analysis: DemandedBitsAnalysis on ssub_no_overflow_due_to_or_conds
 ; CHECK-NEXT: Running pass: RequireAnalysisPass
+; CHECK-NEXT: Running analysis: DemandedBitsAnalysis on ssub_no_overflow_due_to_or_conds
 
 ; CHECK-NEXT: Running pass: RequireAnalysisPass
 ; CHECK-NEXT: Running analysis: DemandedBitsAnalysis on uge_zext


        


More information about the llvm-commits mailing list