Skip to content

Conversation

alexfh
Copy link
Contributor

@alexfh alexfh commented Aug 27, 2025

Reverts #151142

#151142 triggers a crash in the vector-combine pass - #151142 (comment).

@llvmbot
Copy link
Member

llvmbot commented Aug 27, 2025

@llvm/pr-subscribers-llvm-transforms

@llvm/pr-subscribers-backend-arm

Author: Alexander Kornienko (alexfh)

Changes

Reverts llvm/llvm-project#151142

#151142 triggers a crash in the vector-combine pass - #151142 (comment).


Full diff: https://github.com/llvm/llvm-project/pull/155533.diff

7 Files Affected:

  • (modified) llvm/lib/Transforms/Utils/SimplifyCFG.cpp (+6-11)
  • (modified) llvm/test/CodeGen/ARM/2013-05-05-IfConvertBug.ll (+3-3)
  • (modified) llvm/test/Transforms/SimplifyCFG/2008-07-13-InfLoopMiscompile.ll (+2-1)
  • (removed) llvm/test/Transforms/SimplifyCFG/2025-07-29-non-canoncial-loop.ll (-62)
  • (modified) llvm/test/Transforms/SimplifyCFG/branch-phi-thread.ll (+1-1)
  • (modified) llvm/test/Transforms/SimplifyCFG/jump-threading.ll (+1-1)
  • (modified) llvm/test/Transforms/SimplifyCFG/two-entry-phi-return.ll (+1-1)
diff --git a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
index ef110a6922f05..6290423f032b3 100644
--- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
@@ -291,7 +291,6 @@ class SimplifyCFGOpt {
   bool simplifyBranch(BranchInst *Branch, IRBuilder<> &Builder);
   bool simplifyUncondBranch(BranchInst *BI, IRBuilder<> &Builder);
   bool simplifyCondBranch(BranchInst *BI, IRBuilder<> &Builder);
-  bool foldCondBranchOnValueKnownInPredecessor(BranchInst *BI);
 
   bool tryToSimplifyUncondBranchWithICmpInIt(ICmpInst *ICI,
                                              IRBuilder<> &Builder);
@@ -3690,19 +3689,15 @@ foldCondBranchOnValueKnownInPredecessorImpl(BranchInst *BI, DomTreeUpdater *DTU,
   return false;
 }
 
-bool SimplifyCFGOpt::foldCondBranchOnValueKnownInPredecessor(BranchInst *BI) {
-  // Note: If BB is a loop header then there is a risk that threading introduces
-  // a non-canonical loop by moving a back edge. So we avoid this optimization
-  // for loop headers if NeedCanonicalLoop is set.
-  if (Options.NeedCanonicalLoop && is_contained(LoopHeaders, BI->getParent()))
-    return false;
-
+static bool foldCondBranchOnValueKnownInPredecessor(BranchInst *BI,
+                                                    DomTreeUpdater *DTU,
+                                                    const DataLayout &DL,
+                                                    AssumptionCache *AC) {
   std::optional<bool> Result;
   bool EverChanged = false;
   do {
     // Note that None means "we changed things, but recurse further."
-    Result =
-        foldCondBranchOnValueKnownInPredecessorImpl(BI, DTU, DL, Options.AC);
+    Result = foldCondBranchOnValueKnownInPredecessorImpl(BI, DTU, DL, AC);
     EverChanged |= Result == std::nullopt || *Result;
   } while (Result == std::nullopt);
   return EverChanged;
@@ -8123,7 +8118,7 @@ bool SimplifyCFGOpt::simplifyCondBranch(BranchInst *BI, IRBuilder<> &Builder) {
   // If this is a branch on something for which we know the constant value in
   // predecessors (e.g. a phi node in the current block), thread control
   // through this block.
-  if (foldCondBranchOnValueKnownInPredecessor(BI))
+  if (foldCondBranchOnValueKnownInPredecessor(BI, DTU, DL, Options.AC))
     return requestResimplify();
 
   // Scan predecessor blocks for conditional branches.
diff --git a/llvm/test/CodeGen/ARM/2013-05-05-IfConvertBug.ll b/llvm/test/CodeGen/ARM/2013-05-05-IfConvertBug.ll
index 8f798fac06f54..344bb15d2a8b8 100644
--- a/llvm/test/CodeGen/ARM/2013-05-05-IfConvertBug.ll
+++ b/llvm/test/CodeGen/ARM/2013-05-05-IfConvertBug.ll
@@ -1,7 +1,7 @@
 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
-; RUN: llc -keep-loops="false" < %s -mtriple=thumbv7-apple-ios -mcpu=cortex-a8 | FileCheck %s
-; RUN: llc -keep-loops="false" < %s -mtriple=thumbv8 | FileCheck -check-prefix=CHECK-V8 %s
-; RUN: llc -keep-loops="false" < %s -mtriple=thumbv7 -arm-restrict-it | FileCheck -check-prefix=CHECK-RESTRICT-IT %s
+; RUN: llc < %s -mtriple=thumbv7-apple-ios -mcpu=cortex-a8 | FileCheck %s
+; RUN: llc < %s -mtriple=thumbv8 | FileCheck -check-prefix=CHECK-V8 %s
+; RUN: llc < %s -mtriple=thumbv7 -arm-restrict-it | FileCheck -check-prefix=CHECK-RESTRICT-IT %s
 
 define i32 @t1(i32 %a, i32 %b, ptr %retaddr) {
 ; CHECK-LABEL: t1:
diff --git a/llvm/test/Transforms/SimplifyCFG/2008-07-13-InfLoopMiscompile.ll b/llvm/test/Transforms/SimplifyCFG/2008-07-13-InfLoopMiscompile.ll
index 44d92e1a1c210..2e9e7b19c73e2 100644
--- a/llvm/test/Transforms/SimplifyCFG/2008-07-13-InfLoopMiscompile.ll
+++ b/llvm/test/Transforms/SimplifyCFG/2008-07-13-InfLoopMiscompile.ll
@@ -1,5 +1,5 @@
 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
-; RUN: opt < %s -passes=simplifycfg -simplifycfg-require-and-preserve-domtree=1 -keep-loops="false" -S | FileCheck %s
+; RUN: opt < %s -passes=simplifycfg -simplifycfg-require-and-preserve-domtree=1 -S | FileCheck %s
 ; PR2540
 ; Outval should end up with a select from 0/2, not all constants.
 
@@ -52,3 +52,4 @@ func_1.exit:		; preds = %cowblock, %entry
 }
 
 declare i32 @printf(ptr, ...) nounwind
+
diff --git a/llvm/test/Transforms/SimplifyCFG/2025-07-29-non-canoncial-loop.ll b/llvm/test/Transforms/SimplifyCFG/2025-07-29-non-canoncial-loop.ll
deleted file mode 100644
index 322dd98f48df1..0000000000000
--- a/llvm/test/Transforms/SimplifyCFG/2025-07-29-non-canoncial-loop.ll
+++ /dev/null
@@ -1,62 +0,0 @@
-; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
-; RUN: opt < %s -passes=simplifycfg -simplifycfg-require-and-preserve-domtree=1 --keep-loops="true" -S | FileCheck --check-prefix=NO-THREADING %s
-; Checks that we do not thread the control flow through the loop header loop_header as
-; that will introduce a non-canonical loop.
-
-; RUN: opt < %s -passes=simplifycfg -simplifycfg-require-and-preserve-domtree=1 --keep-loops="false" -S | FileCheck --check-prefix=THREADING %s
-; Checks that we thread the control flow through the loop header loop_header since we
-; do not request --keep-loops.
-
-define void @__start(i1 %cond) {
-; NO-THREADING-LABEL: define void @__start(
-; NO-THREADING-SAME: i1 [[COND:%.*]]) {
-; NO-THREADING-NEXT:  [[ENTRY:.*:]]
-; NO-THREADING-NEXT:    br label %[[LOOP_HEADER:.*]]
-; NO-THREADING:       [[LOOP_HEADER]]:
-; NO-THREADING-NEXT:    br i1 [[COND]], label %[[LOOP_BODY_1:.*]], label %[[LOOP_BODY_0:.*]]
-; NO-THREADING:       [[LOOP_BODY_0]]:
-; NO-THREADING-NEXT:    [[_0_:%.*]] = add i16 0, 0
-; NO-THREADING-NEXT:    br label %[[LOOP_EXIT:.*]]
-; NO-THREADING:       [[LOOP_BODY_1]]:
-; NO-THREADING-NEXT:    [[_1_:%.*]] = add i32 0, 1
-; NO-THREADING-NEXT:    br label %[[LOOP_EXIT]]
-; NO-THREADING:       [[LOOP_EXIT]]:
-; NO-THREADING-NEXT:    br i1 [[COND]], label %[[LOOP_HEADER]], label %[[EXIT:.*]]
-; NO-THREADING:       [[EXIT]]:
-; NO-THREADING-NEXT:    ret void
-;
-; THREADING-LABEL: define void @__start(
-; THREADING-SAME: i1 [[COND:%.*]]) {
-; THREADING-NEXT:  [[ENTRY:.*:]]
-; THREADING-NEXT:    br i1 [[COND]], label %[[LOOP_BODY_1:.*]], label %[[LOOP_BODY_0:.*]]
-; THREADING:       [[LOOP_BODY_0]]:
-; THREADING-NEXT:    [[_0_:%.*]] = add i16 0, 0
-; THREADING-NEXT:    br label %[[LOOP_EXIT:.*]]
-; THREADING:       [[LOOP_BODY_1]]:
-; THREADING-NEXT:    [[_1_:%.*]] = add i32 0, 1
-; THREADING-NEXT:    br label %[[LOOP_EXIT]]
-; THREADING:       [[LOOP_EXIT]]:
-; THREADING-NEXT:    br i1 [[COND]], label %[[LOOP_BODY_1]], label %[[EXIT:.*]]
-; THREADING:       [[EXIT]]:
-; THREADING-NEXT:    ret void
-;
-entry:
-  br label %loop_header
-
-loop_header:                                            ; preds = %loop_exit, %entry
-  br i1 %cond, label %loop_body_1, label %loop_body_0
-
-loop_body_0:                                            ; preds = %loop_header
-  %_0_ = add i16 0, 0
-  br label %loop_exit
-
-loop_body_1:                                            ; preds = %loop_header
-  %_1_ = add i32 0, 1
-  br label %loop_exit
-
-loop_exit:                                            ; preds = %loop_body_1, %loop_body_0
-  br i1 %cond, label %loop_header, label %exit
-
-exit:                                            ; preds = %loop_exit
-  ret void
-}
diff --git a/llvm/test/Transforms/SimplifyCFG/branch-phi-thread.ll b/llvm/test/Transforms/SimplifyCFG/branch-phi-thread.ll
index ec9423bd81675..0afec05ecbd6a 100644
--- a/llvm/test/Transforms/SimplifyCFG/branch-phi-thread.ll
+++ b/llvm/test/Transforms/SimplifyCFG/branch-phi-thread.ll
@@ -1,5 +1,5 @@
 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
-; RUN: opt < %s -passes=simplifycfg,adce -simplifycfg-require-and-preserve-domtree=1 -keep-loops="false" -S | FileCheck %s
+; RUN: opt < %s -passes=simplifycfg,adce -simplifycfg-require-and-preserve-domtree=1 -S | FileCheck %s
 
 declare void @f1()
 
diff --git a/llvm/test/Transforms/SimplifyCFG/jump-threading.ll b/llvm/test/Transforms/SimplifyCFG/jump-threading.ll
index a4073ae6eb0b4..50a32413a0551 100644
--- a/llvm/test/Transforms/SimplifyCFG/jump-threading.ll
+++ b/llvm/test/Transforms/SimplifyCFG/jump-threading.ll
@@ -1,5 +1,5 @@
 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
-; RUN: opt -S -passes=simplifycfg -keep-loops="false" < %s | FileCheck %s
+; RUN: opt -S -passes=simplifycfg < %s | FileCheck %s
 
 declare void @foo()
 declare void @bar()
diff --git a/llvm/test/Transforms/SimplifyCFG/two-entry-phi-return.ll b/llvm/test/Transforms/SimplifyCFG/two-entry-phi-return.ll
index f6d71ddda74fe..57930c91b9796 100644
--- a/llvm/test/Transforms/SimplifyCFG/two-entry-phi-return.ll
+++ b/llvm/test/Transforms/SimplifyCFG/two-entry-phi-return.ll
@@ -1,5 +1,5 @@
 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
-; RUN: opt < %s -passes=simplifycfg -simplifycfg-require-and-preserve-domtree=1 -keep-loops="false" -S | FileCheck %s
+; RUN: opt < %s -passes=simplifycfg -simplifycfg-require-and-preserve-domtree=1 -S | FileCheck %s
 
 define i1 @qux(ptr %m, ptr %n, ptr %o, ptr %p) nounwind  {
 ; CHECK-LABEL: @qux(

@dtcxzyw
Copy link
Member

dtcxzyw commented Aug 27, 2025

This patch triggers a bug in vector-combine. But I don't think it should be reverted if it doesn't break the CI.
I have filed #155543 to track the issue. If no one works on it, I will post a fix tonight (UTC+8).

@dtcxzyw
Copy link
Member

dtcxzyw commented Aug 27, 2025

Fixed.

@dtcxzyw dtcxzyw closed this Aug 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants