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

Ramkumar Ramachandra llvmlistbot at llvm.org
Fri Jun 14 02:39:46 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:

On a related note, how do I rewrite `alignTo`, which is `(Value + Align - 1) / Align * Align` to not overflow?

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


More information about the Mlir-commits mailing list