Legalizing: integer promotion with custom expand

Consider the following dag:

              t7: i1 = setcc t4, Constant:i64<1>, seteq:ch
              t12: i1 = setcc t10, Constant:i64<2>, seteq:ch
            t42: i1 = and t7, t12

Here, setcc node is custom expanded, when and is integer promoted.

The problem is that the Legalizer searches promoted integers for operands of ‘and’ instruction in PromotedIntegers map (call GetPromotedInteger for each operand).

But custom expanded nodes are not inserted into this map. And assertion occurred in GetPromotedInteger, when we search t7 and t12 nodes.

I suppose, this case is quite regular and should be well known, but I can’t figure out how to solve it. Please help.


The normal way to handle this is that you custom lower “i1 setcc” to “i1 trunc (i32 target_specific_setcc)”. Then you let the type legalizer eliminate the trunc.

It works! Thank you efriedma-quic

But in my mind, it looks tricky and unclear. I just wonder why not make the PromotedIntegers map visible to custom legalizers? So they can just add fixed nodes to it.

I think it ended up that was as a historical artifact; originally, type legalization didn’t exist, and then as it got introduced it reused existing callbacks, and then once type legalization was working there really wasn’t any incentive to change the callback API.