Skip to content

Commit

Permalink
[Polly] Ensure i1 preload condition
Browse files Browse the repository at this point in the history
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 llvm#123932
  • Loading branch information
Meinersbur committed Jan 27, 2025
1 parent 7b1becd commit 610e33a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
3 changes: 3 additions & 0 deletions polly/include/polly/CodeGen/IslExprBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
7 changes: 7 additions & 0 deletions polly/lib/CodeGen/IslExprBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
2 changes: 1 addition & 1 deletion polly/lib/CodeGen/IslNodeBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down

0 comments on commit 610e33a

Please sign in to comment.