[llvm] [SimpleLoopUnswitch] Fix bug in partially invariant unswitching (PR #222118)
Ehsan Amiri via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 8 12:47:29 PDT 2026
https://github.com/amehsan created https://github.com/llvm/llvm-project/pull/222118
First commit checks in the testcase and runs the CI to show the current implementation has a bug. I will commit the fix after CI finished for the first commit.
>From e25c5be1ec1bd99070da6d42e0da05474f155cb0 Mon Sep 17 00:00:00 2001
From: Ehsan Amiri <ehsan.amiri at huawei.com>
Date: Thu, 3 Sep 2026 15:25:41 -0400
Subject: [PATCH] add the failing testcase
---
.../Transforms/SimpleLoopUnswitch/pr219510.ll | 34 +++++++++++++++++++
1 file changed, 34 insertions(+)
create mode 100644 llvm/test/Transforms/SimpleLoopUnswitch/pr219510.ll
diff --git a/llvm/test/Transforms/SimpleLoopUnswitch/pr219510.ll b/llvm/test/Transforms/SimpleLoopUnswitch/pr219510.ll
new file mode 100644
index 0000000000000..555bfc1d992cc
--- /dev/null
+++ b/llvm/test/Transforms/SimpleLoopUnswitch/pr219510.ll
@@ -0,0 +1,34 @@
+; RUN: opt -passes='loop-mssa(simple-loop-unswitch<nontrivial>)' -S < %s | FileCheck %s
+
+declare void @barrier() memory(read)
+declare void @clobber()
+
+; CHECK: call void @barrier()
+; CHECK-NEXT: %lv = load i32, ptr %ptr
+
+
+define i32 @bad_unswitch(ptr %ptr, i32 %N) {
+entry:
+ br label %loop.header
+loop.header:
+ %iv = phi i32 [ 0, %entry ], [ %iv.next, %loop.latch ]
+ call void @barrier()
+ %lv = load i32, ptr %ptr
+ %sc = icmp eq i32 %lv, 100
+ br i1 %sc, label %noclobber, label %clobber
+
+noclobber:
+ br label %loop.latch
+
+clobber:
+ call void @clobber()
+ br label %loop.latch
+
+loop.latch:
+ %c = icmp ult i32 %iv, %N
+ %iv.next = add i32 %iv, 1
+ br i1 %c, label %loop.header, label %exit
+
+exit:
+ ret i32 10
+}
More information about the llvm-commits
mailing list