[llvm] [ConstraintElim] Drop invalid rows instead of failing the elimination (PR #76299)

Yingwei Zheng via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 28 09:38:11 PST 2023


https://github.com/dtcxzyw updated https://github.com/llvm/llvm-project/pull/76299

>From 87bd17c8a242f3333a22fa13336601c6a4084507 Mon Sep 17 00:00:00 2001
From: Yingwei Zheng <dtcxzyw2333 at gmail.com>
Date: Fri, 29 Dec 2023 01:37:45 +0800
Subject: [PATCH] [ConstraintElim] Drop invalid rows instead of failing the
 elimination

---
 llvm/lib/Analysis/ConstraintSystem.cpp             | 14 ++++++++------
 .../ConstraintElimination/constraint-overflow.ll   |  3 +--
 2 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/llvm/lib/Analysis/ConstraintSystem.cpp b/llvm/lib/Analysis/ConstraintSystem.cpp
index 35bdd869a88d1a..729d1e952af18b 100644
--- a/llvm/lib/Analysis/ConstraintSystem.cpp
+++ b/llvm/lib/Analysis/ConstraintSystem.cpp
@@ -95,17 +95,19 @@ bool ConstraintSystem::eliminateUsingFM() {
           IdxUpper++;
         }
 
-        if (MulOverflow(UpperV, ((-1) * LowerLast), M1))
-          return false;
+        if (MulOverflow(UpperV, (-1) * LowerLast, M1)) {
+          NR.clear();
+          break;
+        }
         if (IdxLower < LowerRow.size() && LowerRow[IdxLower].Id == CurrentId) {
           LowerV = LowerRow[IdxLower].Coefficient;
           IdxLower++;
         }
 
-        if (MulOverflow(LowerV, (UpperLast), M2))
-          return false;
-        if (AddOverflow(M1, M2, N))
-          return false;
+        if (MulOverflow(LowerV, UpperLast, M2) || AddOverflow(M1, M2, N)) {
+          NR.clear();
+          break;
+        }
         if (N == 0)
           continue;
         NR.emplace_back(N, CurrentId);
diff --git a/llvm/test/Transforms/ConstraintElimination/constraint-overflow.ll b/llvm/test/Transforms/ConstraintElimination/constraint-overflow.ll
index 88f87f4afab286..efb89fd0512d96 100644
--- a/llvm/test/Transforms/ConstraintElimination/constraint-overflow.ll
+++ b/llvm/test/Transforms/ConstraintElimination/constraint-overflow.ll
@@ -13,8 +13,7 @@ define i32 @f(i64 %a3, i64 %numElements) {
 ; CHECK-NEXT:    [[CMP:%.*]] = icmp ugt i64 [[A1]], [[A3]]
 ; CHECK-NEXT:    br i1 [[CMP]], label [[IF_END_I:%.*]], label [[ABORT:%.*]]
 ; CHECK:       if.end.i:
-; CHECK-NEXT:    [[CMP2_NOT_I:%.*]] = icmp ult i64 [[A1]], [[A3]]
-; CHECK-NEXT:    br i1 [[CMP2_NOT_I]], label [[ABORT]], label [[EXIT:%.*]]
+; CHECK-NEXT:    br i1 false, label [[ABORT]], label [[EXIT:%.*]]
 ; CHECK:       abort:
 ; CHECK-NEXT:    ret i32 -1
 ; CHECK:       exit:



More information about the llvm-commits mailing list