[LLVMdev] Assert in SelectionDAGLegalize when using arbitrary size integers

Emmanuel Viaud
Wed, 25 Jun 2008 09:41:58 -0000

Hi.

I am beginning to learn LLVM (using LLVM 2.3.0 on a Linux x86_64
machine) and wanted to check the status of the support of arbitrary
size integers.
To do so, I tried to modify the HowToUseJIT example by replacing the
Int32Ty with another size (let's say 12 bits for the example). While
it compiles ok, I get the following assert at run-time:

HowToUseJIT: LegalizeDAG.cpp:4059: llvm::SDOperand
<unnamed>::SelectionDAGLegalize::PromoteOp(llvm::SDOperand): Assertion
`NVT > VT && MVT::isInteger(NVT) == MVT::isInteger(VT) &&
"Cannot
promote to smaller type!"' failed.

The corresponding code is the following:
 SDOperand SelectionDAGLegalize::PromoteOp(SDOperand Op) {
  MVT::ValueType VT = Op.getValueType();
  MVT::ValueType NVT = TLI.getTypeToTransformTo(VT);
  assert(getTypeAction(VT) == Promote &&
         "Caller should expand or legalize operands that are not
promotable!");
  assert(NVT > VT && MVT::isInteger(NVT) == MVT::isInteger(VT)
&&
         "Cannot promote to smaller type!");

The assert fails in the first test. When trying to understand the
bahaviour, I saw that :
 - VT value is 0xBFE : OK because 0xB is (bitwidth-1) and 0xFE is
MVT::iAny from MVT::SimpleValueType
 - NVT value is 3 : OK because 3 = MVT::i16 from MVT::SimpleValueType

What I don't really understand is the meaning of that first test in
the assert : 'NVT > VT'. As in that case VT is always >= MVT::iAny
and
NVT is <= MVT::LAST_VALUETYPE, the test is always false.

So did I miss something obvious, does that simply mean that the
PromoteOp method doesn't deal yet with arbitrary size integers or is
there a problem in the assert condition?

Sorry for the maybe naive question and thanks for any information on
the subject.

Best regards,
Emmanuel.