[Mlir-commits] [flang] [mlir] [MLIR][OpenMP] Fix type mismatch in linear clause for INTEGER(8) variables (PR #173982)
Krish Gupta
llvmlistbot at llvm.org
Thu Jan 1 10:30:23 PST 2026
================
@@ -187,17 +187,37 @@ class LinearClauseProcessor {
llvm::Value *loopInductionVar) {
builder.SetInsertPoint(loopBody->getTerminator());
for (size_t index = 0; index < linearPreconditionVars.size(); index++) {
- // Emit increments for linear vars
- llvm::LoadInst *linearVarStart = builder.CreateLoad(
- linearVarTypes[index], linearPreconditionVars[index]);
- auto mulInst = builder.CreateMul(loopInductionVar, linearSteps[index]);
- if (linearVarTypes[index]->isIntegerTy()) {
- auto addInst = builder.CreateAdd(linearVarStart, mulInst);
+ llvm::Type *linearVarType = linearVarTypes[index];
+ llvm::Value *iv = loopInductionVar;
+ llvm::Value *step = linearSteps[index];
+
+ if (!iv->getType()->isIntegerTy())
+ llvm_unreachable("OpenMP loop induction variable must be an integer "
+ "type");
+
+ if (linearVarType->isIntegerTy()) {
+ // Integer path: normalize all arithmetic to linearVarType
+ iv = builder.CreateSExtOrTrunc(iv, linearVarType);
----------------
KrxGu wrote:
The current approach normalizes all values to `linearVarType` upfront, ensuring both the multiplication and addition operate in the same type (the linear variable's type). If we only cast step to match iv, we'd still need to extend the multiplication result before adding to linearVarStart, adding extra conversion steps. This approach follows the feedback to normalize to `linearVarTypes[index]` for consistenc
https://github.com/llvm/llvm-project/pull/173982
More information about the Mlir-commits
mailing list