From 610e33a547751019ff514d34f95f72d58118249c Mon Sep 17 00:00:00 2001 From: Michael Kruse Date: Mon, 27 Jan 2025 17:35:38 +0100 Subject: [PATCH] [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 --- polly/include/polly/CodeGen/IslExprBuilder.h | 3 +++ polly/lib/CodeGen/IslExprBuilder.cpp | 7 +++++++ polly/lib/CodeGen/IslNodeBuilder.cpp | 2 +- 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/polly/include/polly/CodeGen/IslExprBuilder.h b/polly/include/polly/CodeGen/IslExprBuilder.h index 25f61be5787c1..df8140e0b8757 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 1688c41c624b2..8c54436f295b3 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 bbe7bc42cd833..40205215ea0b3 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");