SelectionDAG constant folding leads to assertion failure

My experimental code calls DAG.getNode to construct a unary node with
a flag result. Unfortunately the argument turns out to be constant, so
lib/CodeGen/SelectionDAG/SelectionDAG.cpp:2332 calls VT.getSizeInBits
on the flag type, which isSimple(), so we call V.getSizeInBits at
ValueTypes.h:560 and fail at ValueTypes.h:240:

clang: .../include/llvm/CodeGen/ValueTypes.h:240: unsigned int
llvm::MVT::getSizeInBits() const: Assertion `0 && "getSizeInBits called
on extended MVT."' failed.

The message is misleading as Flag is not an extended MVT.

I would guess that normally constant folding would have happened
earlier on, but it would be nice if I could call DAG.getNode with
constant arguments without this happening.

Could getSizeInBits() return 0 or -1 for a Flag? Or should
SelectionDAG::getNode not call getSizeInBits until it knows it
actually needs the value?

My experimental code calls DAG.getNode to construct a unary node with
a flag result. Unfortunately the argument turns out to be constant, so
lib/CodeGen/SelectionDAG/SelectionDAG.cpp:2332 calls VT.getSizeInBits
on the flag type, which isSimple(), so we call V.getSizeInBits at
ValueTypes.h:560 and fail at ValueTypes.h:240:

That's bad. :slight_smile:

Or should
SelectionDAG::getNode not call getSizeInBits until it knows it
actually needs the value?

You're right, fixed in r98547, thanks!

-Chris