[Mlir-commits] [llvm] [mlir] MathExtras: avoid unnecessarily widening types (PR #95426)

Ramkumar Ramachandra llvmlistbot at llvm.org
Fri Jun 14 00:41:23 PDT 2024


================
@@ -986,7 +986,9 @@ unsigned getMaxFlatWorkGroupSize(const MCSubtargetInfo *STI) {
 
 unsigned getWavesPerWorkGroup(const MCSubtargetInfo *STI,
                               unsigned FlatWorkGroupSize) {
-  return divideCeil(FlatWorkGroupSize, getWavefrontSize(STI));
+  // divideCeil will overflow, unless FlatWorkGroupSize is cast.
+  return divideCeil(static_cast<uint64_t>(FlatWorkGroupSize),
+                    getWavefrontSize(STI));
----------------
artagnon wrote:

I was also surprised, but the assertion is hit in CodeGen/AMDGPU/codegen-internal-only-func.ll.

Orthogonal, but we could probably get divideCeil to never overflow, using some clever addition/subtraction.

https://github.com/llvm/llvm-project/pull/95426


More information about the Mlir-commits mailing list