Skip to content

Commit 610e33a

Browse files
committed
[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
1 parent 7b1becd commit 610e33a

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

polly/include/polly/CodeGen/IslExprBuilder.h

+3
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,9 @@ class IslExprBuilder final {
135135
/// @return The llvm::Value* containing the result of the computation.
136136
llvm::Value *create(__isl_take isl_ast_expr *Expr);
137137

138+
/// Create LLVM-IR for an isl_ast_expr[ession] and cast it to i1.
139+
llvm::Value *createBool(__isl_take isl_ast_expr *Expr);
140+
138141
/// Return the largest of two types.
139142
///
140143
/// @param T1 The first type.

polly/lib/CodeGen/IslExprBuilder.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -790,3 +790,10 @@ Value *IslExprBuilder::create(__isl_take isl_ast_expr *Expr) {
790790

791791
llvm_unreachable("Unexpected enum value");
792792
}
793+
794+
llvm::Value *IslExprBuilder::createBool(__isl_take isl_ast_expr *Expr) {
795+
Value *Result = create(Expr);
796+
if (!Result->getType()->isIntegerTy(1))
797+
Result = Builder.CreateICmpNE(Result, Builder.getInt1(false));
798+
return Result;
799+
}

polly/lib/CodeGen/IslNodeBuilder.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1103,7 +1103,7 @@ Value *IslNodeBuilder::preloadInvariantLoad(const MemoryAccess &MA,
11031103
Domain = nullptr;
11041104

11051105
ExprBuilder.setTrackOverflow(true);
1106-
Value *Cond = ExprBuilder.create(DomainCond);
1106+
Value *Cond = ExprBuilder.createBool(DomainCond);
11071107
Value *OverflowHappened = Builder.CreateNot(ExprBuilder.getOverflowState(),
11081108
"polly.preload.cond.overflown");
11091109
Cond = Builder.CreateAnd(Cond, OverflowHappened, "polly.preload.cond.result");

0 commit comments

Comments
 (0)