[flang-commits] [flang] [mlir] [MLIR][OpenMP] Fix type mismatch in linear clause for INTEGER(8) variables (PR #173982)
Krzysztof Parzyszek via flang-commits
flang-commits at lists.llvm.org
Wed Dec 31 09:28:23 PST 2025
================
@@ -187,17 +187,45 @@ 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];
+
+ // Helper to cast signed integers with sign extension or truncation
+ auto castSignedInt = [&](llvm::Value *val,
+ llvm::Type *targetType) -> llvm::Value * {
+ if (val->getType() == targetType)
+ return val;
+ return builder.CreateSExtOrTrunc(val, targetType);
+ };
+
+ if (linearVarType->isIntegerTy()) {
+ // Integer path: normalize all arithmetic to linearVarType
+ iv = castSignedInt(iv, linearVarType);
+ step = castSignedInt(step, linearVarType);
+
+ llvm::LoadInst *linearVarStart =
+ builder.CreateLoad(linearVarType, linearPreconditionVars[index]);
+ llvm::Value *mulInst = builder.CreateMul(iv, step);
+ llvm::Value *addInst = builder.CreateAdd(linearVarStart, mulInst);
builder.CreateStore(addInst, linearLoopBodyTemps[index]);
- } else if (linearVarTypes[index]->isFloatingPointTy()) {
- auto cvt = builder.CreateSIToFP(mulInst, linearVarTypes[index]);
- auto addInst = builder.CreateFAdd(linearVarStart, cvt);
+ } else if (linearVarType->isFloatingPointTy()) {
+ // Float path: perform multiply in integer, then convert to float
+ llvm::Type *ivType = iv->getType();
+ if (!ivType->isIntegerTy())
+ llvm_unreachable("OpenMP loop induction variable must be an integer "
+ "type when updating floating-point linear vars");
----------------
kparzysz wrote:
If this is a legitimate concern, it should be checked in both cases.
https://github.com/llvm/llvm-project/pull/173982
More information about the flang-commits
mailing list