[Mlir-commits] [mlir] [mlir][scf] Fix unsigned narrow type trip count calculation (PR #178060)
Jhalak Patel
llvmlistbot at llvm.org
Tue Jan 27 12:04:05 PST 2026
================
@@ -391,12 +394,22 @@ std::optional<APInt> constantTripCount(
return std::nullopt;
}
auto &stepCst = maybeStepCst->first;
- llvm::APInt tripCount = isSigned ? diff.sdiv(stepCst) : diff.udiv(stepCst);
- llvm::APInt remainder = isSigned ? diff.srem(stepCst) : diff.urem(stepCst);
+ // Create new APSInt instances with explicit signedness to ensure they match
+ llvm::APSInt diffSigned(diff, /*isUnsigned=*/!isSigned);
----------------
jhalakpatel wrote:
Yes the original implementation was correct. I originally thought it would cleaner to encoded the signedness in int type and let the operations (/ or %) dispatch to the correct implementation.
Now that I look again, later we do ` APInt result = tripCount;` which seems confusing since we are converting APSInt back to APInt. I will revert to original change here.
https://github.com/llvm/llvm-project/pull/178060
More information about the Mlir-commits
mailing list