[PATCH] D109721: [IR] Reduce max supported integer from 2^24-1 to 2^23.

Craig Topper via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 13 13:50:34 PDT 2021


craig.topper created this revision.
craig.topper added reviewers: efriedma, erichkeane, aaron.ballman.
Herald added subscribers: dexonsmith, jdoerfert.
craig.topper requested review of this revision.
Herald added a project: LLVM.

SelectionDAG will promote illegal types up to a power of 2 before
splitting down to a legal type. This will create an IntegerType
with a bit width that must be <= MAX_INT_BITS. This places an
effective upper limit on any type of 2^23 so that we don't try
create a 2^24 type.

I considered putting a fatal error somewhere in the path from
TargetLowering::getTypeConversion down to IntegerType::get, but
limiting the type in IR seemed better.

This breaks backwards compatibility with IR that is using a really
large type. I suspect such IR is going to be very rare due to the
the compile time costs such a type likely incurs.

Prevents the ICE in PR51829.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D109721

Files:
  llvm/docs/LangRef.rst
  llvm/docs/ReleaseNotes.rst
  llvm/include/llvm/IR/DerivedTypes.h
  llvm/test/Assembler/invalid-inttype.ll
  llvm/test/Assembler/max-inttype.ll


Index: llvm/test/Assembler/max-inttype.ll
===================================================================
--- llvm/test/Assembler/max-inttype.ll
+++ llvm/test/Assembler/max-inttype.ll
@@ -1,4 +1,4 @@
 ; RUN: llvm-as < %s | llvm-dis
 
-; i16777215 is the maximum integer type represented in LLVM IR
- at i2 = common global i16777215 0, align 4
+; i838608 is the maximum integer type represented in LLVM IR
+ at i2 = common global i838608 0, align 4
Index: llvm/test/Assembler/invalid-inttype.ll
===================================================================
--- llvm/test/Assembler/invalid-inttype.ll
+++ llvm/test/Assembler/invalid-inttype.ll
@@ -1,5 +1,5 @@
 ; RUN: not llvm-as < %s 2>&1 | FileCheck %s
 
-; i16777216 is the smallest integer type that can't be represented in LLVM IR
- at i2 = common global i16777216 0, align 4
+; i8388609 is the smallest integer type that can't be represented in LLVM IR
+ at i2 = common global i8388609 0, align 4
 ; CHECK: expected type
Index: llvm/include/llvm/IR/DerivedTypes.h
===================================================================
--- llvm/include/llvm/IR/DerivedTypes.h
+++ llvm/include/llvm/IR/DerivedTypes.h
@@ -49,10 +49,11 @@
   /// This enum is just used to hold constants we need for IntegerType.
   enum {
     MIN_INT_BITS = 1,        ///< Minimum number of bits that can be specified
-    MAX_INT_BITS = (1<<24)-1 ///< Maximum number of bits that can be specified
+    MAX_INT_BITS = (1<<23)   ///< Maximum number of bits that can be specified
       ///< Note that bit width is stored in the Type classes SubclassData field
-      ///< which has 24 bits. This yields a maximum bit width of 16,777,215
-      ///< bits.
+      ///< which has 24 bits. SelectionDAG type legalization can require a
+      ///< power of 2 IntegerType, so limit to the largest representable power
+      ///< of 2, 8388608.
   };
 
   /// This static method is the primary way of constructing an IntegerType.
Index: llvm/docs/ReleaseNotes.rst
===================================================================
--- llvm/docs/ReleaseNotes.rst
+++ llvm/docs/ReleaseNotes.rst
@@ -59,6 +59,7 @@
 * Using the legacy pass manager for the optimization pipeline is deprecated and
   will be removed after LLVM 14. In the meantime, only minimal effort will be
   made to maintain the legacy pass manager for the optimization pipeline.
+* Max allowed integer type was reduced from 2^24-1 bits to 2^23 bits.
 
 Changes to building LLVM
 ------------------------
Index: llvm/docs/LangRef.rst
===================================================================
--- llvm/docs/LangRef.rst
+++ llvm/docs/LangRef.rst
@@ -3303,7 +3303,7 @@
 
 The integer type is a very simple type that simply specifies an
 arbitrary bit width for the integer type desired. Any bit width from 1
-bit to 2\ :sup:`23`\ -1 (about 8 million) can be specified.
+bit to 2\ :sup:`23`\ (about 8 million) can be specified.
 
 :Syntax:
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D109721.372337.patch
Type: text/x-patch
Size: 2936 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210913/21c82a54/attachment.bin>


More information about the llvm-commits mailing list