[polly] [Polly] Correct integer comparison bit width (PR #190493)
Michael Kruse via llvm-commits
llvm-commits at lists.llvm.org
Sun Apr 5 17:54:56 PDT 2026
https://github.com/Meinersbur updated https://github.com/llvm/llvm-project/pull/190493
>From cdc0f98d094337f080c017a377d7684d7a728871 Mon Sep 17 00:00:00 2001
From: Michael Kruse <llvm-project at meinersbur.de>
Date: Sun, 5 Apr 2026 00:16:41 +0200
Subject: [PATCH 1/2] [Polly] correct ineger comparison bit width
---
polly/lib/CodeGen/IslExprBuilder.cpp | 3 ++-
polly/test/CodeGen/issue190459_1.ll | 26 ++++++++++++++++++++++++++
2 files changed, 28 insertions(+), 1 deletion(-)
create mode 100644 polly/test/CodeGen/issue190459_1.ll
diff --git a/polly/lib/CodeGen/IslExprBuilder.cpp b/polly/lib/CodeGen/IslExprBuilder.cpp
index 01e252d51223b..ca5a82fd5fa8e 100644
--- a/polly/lib/CodeGen/IslExprBuilder.cpp
+++ b/polly/lib/CodeGen/IslExprBuilder.cpp
@@ -794,6 +794,7 @@ Value *IslExprBuilder::create(__isl_take isl_ast_expr *Expr) {
llvm::Value *IslExprBuilder::createBool(__isl_take isl_ast_expr *Expr) {
Value *Result = create(Expr);
if (!Result->getType()->isIntegerTy(1))
- Result = Builder.CreateICmpNE(Result, Builder.getInt1(false));
+ Result =
+ Builder.CreateICmpNE(Result, ConstantInt::get(Result->getType(), 0));
return Result;
}
diff --git a/polly/test/CodeGen/issue190459_1.ll b/polly/test/CodeGen/issue190459_1.ll
new file mode 100644
index 0000000000000..e41c467671633
--- /dev/null
+++ b/polly/test/CodeGen/issue190459_1.ll
@@ -0,0 +1,26 @@
+; RUN: opt %loadNPMPolly '-passes=polly-custom<codegen>' -polly-invariant-load-hoisting -S < %s | FileCheck %s
+
+; https://github.com/llvm/llvm-project/issues/190459
+; Avoid a crash due to comparing integers with different widths
+
+; CHECK: br i1 false, label %polly.preload.exec, label %polly.preload.merge
+
+target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
+
+define i32 @func(i32 %arg) {
+bb:
+ br label %bb1
+
+bb1: ; preds = %bb
+ store i16 0, ptr null, align 2
+ %i = icmp eq i32 %arg, 0
+ br i1 %i, label %bb2, label %bb5
+
+bb2: ; preds = %bb1
+ %i3 = load ptr, ptr null, align 8
+ %i4 = load i16, ptr %i3, align 2
+ br label %bb5
+
+bb5: ; preds = %bb2, %bb1
+ ret i32 0
+}
>From a076c895b5a2219a2d01a8012be2b3939e489abc Mon Sep 17 00:00:00 2001
From: Michael Kruse <github at meinersbur.de>
Date: Mon, 6 Apr 2026 02:54:46 +0200
Subject: [PATCH 2/2] Clarify comparison result in issue190459_1.ll
Add a comment to clarify the result of the comparison.
---
polly/test/CodeGen/issue190459_1.ll | 1 +
1 file changed, 1 insertion(+)
diff --git a/polly/test/CodeGen/issue190459_1.ll b/polly/test/CodeGen/issue190459_1.ll
index e41c467671633..6f511ddffc05b 100644
--- a/polly/test/CodeGen/issue190459_1.ll
+++ b/polly/test/CodeGen/issue190459_1.ll
@@ -3,6 +3,7 @@
; https://github.com/llvm/llvm-project/issues/190459
; Avoid a crash due to comparing integers with different widths
+; "i1 false" is the result of the comparison with the fixed width
; CHECK: br i1 false, label %polly.preload.exec, label %polly.preload.merge
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
More information about the llvm-commits
mailing list