[polly] 610e33a - [Polly] Ensure i1 preload condition

Michael Kruse via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 27 09:55:31 PST 2025


Author: Michael Kruse
Date: 2025-01-27T18:47:12+01:00
New Revision: 610e33a547751019ff514d34f95f72d58118249c

URL: https://github.com/llvm/llvm-project/commit/610e33a547751019ff514d34f95f72d58118249c
DIFF: https://github.com/llvm/llvm-project/commit/610e33a547751019ff514d34f95f72d58118249c.diff

LOG: [Polly] Ensure i1 preload condition

If the preload condition is a constant, ExprBuilder::create returns an
integer of the native integer while an i1 is expected. Cast the result
to i1 if that happens.

Fixes #123932

Added: 
    

Modified: 
    polly/include/polly/CodeGen/IslExprBuilder.h
    polly/lib/CodeGen/IslExprBuilder.cpp
    polly/lib/CodeGen/IslNodeBuilder.cpp

Removed: 
    


################################################################################
diff  --git a/polly/include/polly/CodeGen/IslExprBuilder.h b/polly/include/polly/CodeGen/IslExprBuilder.h
index 25f61be5787c13..df8140e0b87570 100644
--- a/polly/include/polly/CodeGen/IslExprBuilder.h
+++ b/polly/include/polly/CodeGen/IslExprBuilder.h
@@ -135,6 +135,9 @@ class IslExprBuilder final {
   /// @return The llvm::Value* containing the result of the computation.
   llvm::Value *create(__isl_take isl_ast_expr *Expr);
 
+  /// Create LLVM-IR for an isl_ast_expr[ession] and cast it to i1.
+  llvm::Value *createBool(__isl_take isl_ast_expr *Expr);
+
   /// Return the largest of two types.
   ///
   /// @param T1 The first type.

diff  --git a/polly/lib/CodeGen/IslExprBuilder.cpp b/polly/lib/CodeGen/IslExprBuilder.cpp
index 1688c41c624b24..8c54436f295b36 100644
--- a/polly/lib/CodeGen/IslExprBuilder.cpp
+++ b/polly/lib/CodeGen/IslExprBuilder.cpp
@@ -790,3 +790,10 @@ Value *IslExprBuilder::create(__isl_take isl_ast_expr *Expr) {
 
   llvm_unreachable("Unexpected enum value");
 }
+
+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));
+  return Result;
+}

diff  --git a/polly/lib/CodeGen/IslNodeBuilder.cpp b/polly/lib/CodeGen/IslNodeBuilder.cpp
index bbe7bc42cd8338..40205215ea0b31 100644
--- a/polly/lib/CodeGen/IslNodeBuilder.cpp
+++ b/polly/lib/CodeGen/IslNodeBuilder.cpp
@@ -1103,7 +1103,7 @@ Value *IslNodeBuilder::preloadInvariantLoad(const MemoryAccess &MA,
   Domain = nullptr;
 
   ExprBuilder.setTrackOverflow(true);
-  Value *Cond = ExprBuilder.create(DomainCond);
+  Value *Cond = ExprBuilder.createBool(DomainCond);
   Value *OverflowHappened = Builder.CreateNot(ExprBuilder.getOverflowState(),
                                               "polly.preload.cond.overflown");
   Cond = Builder.CreateAnd(Cond, OverflowHappened, "polly.preload.cond.result");


        


More information about the llvm-commits mailing list