Legalizing: promoted nodes in `load's` operands

Hi all,

I have the following load instruction:

t7: i64,ch = load<(dereferenceable load (s64) from @Func, !tbaa !2)> t0, GlobalAddress:i64<ptr @Func> 0, undef:i64

Only i256 is a legal type in my Machine.
Legalization actions are as follows:

  • load: promote
  • GlobalAddress: custom
  • undef: promote

Everything works fine except undef, which is the Offset operand in load. It is promoted to i256, but load still uses the old node. So legalizer calls PromoteIntegerOperand for load node, but load is not supported in this function (no case in switch statement) and it crashes in llvm_unreachable("Do not know how to promote this operator's operand!");.
Here is how the load looks before the crash:

t20: i256 = TargetGlobalAddress:i256<ptr @Func> 0
i256,ch = load<(dereferenceable load (s64) from @Func, !tbaa !2), zext from i64> t0, t20, undef:i64

I can’t understand how it is supposed to work for promoted load’s operands. Since promoted nodes don’t replace its uses, so load will still use old operands, that force legalizer to call PromoteIntegerOperand for load, but PromoteIntegerOperand doesn’t support load node…
Ok, I can make custom legalization of undef, and it will work. But there are another cases when load’s operands are promoted, e.g. add node. I don’t think it is a good idea to make custom legalization for all of them.

Uhhh I’m stuck :exploding_head: Please help.

You’ll just have to implement this; requiring promotion of the offset operand is quite unusual

You mean implement custom lowering of Load?

No, I mean implement the handling in PromoteIntegerOperand for load, as the error directly states it doesn’t know how to do. Adding the handling should be straightforward like other promote operations

Got it, will try. Thanks.
Usually, I try to not alter common LLVM code, but if there are no more options, then ok.