[llvm] [Transforms] Resolve FIXME: Pick the smallest legal type that fits (PR #79158)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 26 08:44:53 PST 2024


================
@@ -382,9 +382,18 @@ bool Float2IntPass::validateAndTransform() {
       continue;
     }
 
-    // OK, R is known to be representable. Now pick a type for it.
-    // FIXME: Pick the smallest legal type that will fit.
-    Type *Ty = (MinBW > 32) ? Type::getInt64Ty(*Ctx) : Type::getInt32Ty(*Ctx);
+    // OK, R is known to be representable.
+    // Pick the smallest legal type that will fit.
+    Type *Ty;
+    if (MinBW <= 8) {
+      Ty = Type::getInt8Ty(*Ctx);
+    } else if (MinBW <= 16) {
+      Ty = Type::getInt16Ty(*Ctx);
+    } else if (MinBW <= 32) {
+      Ty = Type::getInt32Ty(*Ctx);
+    } else {
+      Ty = Type::getInt64Ty(*Ctx);
+    }
----------------
nikic wrote:

This needs to be based on the legal integer types provided by DataLayout.

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


More information about the llvm-commits mailing list