LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 1270 - Support AP integers in the code generator
Summary: Support AP integers in the code generator
Status: RESOLVED FIXED
Alias: None
Product: libraries
Classification: Unclassified
Component: Common Code Generator Code (show other bugs)
Version: trunk
Hardware: All All
: P enhancement
Assignee: Unassigned LLVM Bugs
URL:
Keywords: new-feature
Depends on: 1462
Blocks:
  Show dependency tree
 
Reported: 2007-03-24 16:28 PDT by Reid Spencer
Modified: 2009-04-22 04:35 PDT (History)
3 users (show)

See Also:
Fixed By Commit(s):


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Reid Spencer 2007-03-24 16:28:24 PDT
Currently, the various targets only handle arbitrary precision integers of
discrete byte sizes (1, 2, 4, 8 bytes). However, the LLVM IR can now handle
integer bit widths from 1 bit to 8 million bits. In cases where the integer bit
size doesn't match the discrete byte size of a "known" integer, the common code
generator will generate an assertion because the integer size doesn't map to
something the machine recognizes.

This problem needs to be fixed because:

a) it prevents codegen for programs with "funny" bit sizes.
b) it prevents bit-size optimizations from working. For example, a bit size
   minimization pass might be able to determine that an i32 value really only
   needs 14 bits. It would thus fit into an i16 instead of an i32. However the
   pass would generate i14 which would cause the common code gen to assert.
Comment 1 Reid Spencer 2007-04-10 10:45:37 PDT
Some additional notes:

1. The <= 64bits case should be done separately from the >64 bits case. This
   can be done in terms of the machine's native integer instructions and can
   probably be done in lib/CodeGen without affecting the targets by simply
   adding the needed ext/trunc nodes.

2. For the > 64 bits case, a much more complicated code gen is required to
   handle multi-word arithmetic (e.g. look at APInt::KnuthDivide). With some
   help from TargetData it might be possible to write some lowering code that
   generates the complicated goop necessary, but its more likely that some 
   kind of runtime support (GMP?) is needed for this.

3. Two intrinsics need to be implemented: part_set and part_select.
Comment 2 Chris Lattner 2007-04-10 11:37:18 PDT
The code generator already has partial support for i128 as well.

Supporting arbitrary width integers should be done the same way we support arbitrary width vectors: 
SDISel should lower to an MVT::Integer type, then legalize should turn these into specific supported 
widths.

As usual with legalize, it can turn the operations into open-coded instructions or into libcalls.  We 
obviously won't be able to use the GCC runtime library for the > 64 case, but that's an implementation 
detail.

-Chris
Comment 3 Reid Spencer 2007-04-13 23:33:32 PDT
> Supporting arbitrary width integers should be done the same way we support
> arbitrary width vectors: SDISel should lower to an MVT::Integer type, then
> legalize should turn these into specific supported widths.

Are you saying you want a new MVT::Integer type that represents an arbitrary
precision integer type? If so, where does the width of the type get stored? IIRC
MVT is just an enum. 
Comment 4 Chris Lattner 2007-04-14 00:49:36 PDT
yes, that is what I'm saying.  It gets stored in the operand list, and we use special opcodes, just like 
vectors do with VADD etc.
Comment 5 Chris Lattner 2008-02-18 00:57:12 PST
Dan is working on this, at least for 128-bit integers.  Supporting arbitrary strange sizes is probably blocked on LegalizeDAGTypes being finished.
Comment 6 Duncan Sands 2008-02-18 02:25:02 PST
This is basically done, except for >64 bit constants (which is what Dan
is working on).  It is waiting on LegalizeTypes however.  Also, there is
a maximum bitwidth of 256 bits, which could easily be increased by stealing
some more bits from extended vector types.
Comment 7 Dan Gohman 2008-04-18 20:47:48 PDT
Support for >64 bit constants in codegen is done. 
Comment 8 Duncan Sands 2009-04-22 04:35:43 PDT
This is done now that LegalizeTypes has landed.