[PATCH] D114895: [SelectionDagBuilder] improve CallBrInst BlockAddress constraint handling

Bill Wendling via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 7 16:32:04 PST 2021


void added a comment.

In D114895#3177794 <https://reviews.llvm.org/D114895#3177794>, @efriedma wrote:

> In D114895#3170282 <https://reviews.llvm.org/D114895#3170282>, @nickdesaulniers wrote:
>
>> Unless you can tie a block address. Hopefully `"+r"(&&goto_label)` isn't a valid output constraint...
>>
>>   void x(void) {
>>       asm goto ("":"+r"(&&foo):::foo);
>>       //                ^ error: lvalue required in 'asm' statement
>>       foo:;
>>   }
>
> I think you meant to write something like this:
>
>   void *x(void) {
>       void *p = &&foo;
>       asm goto ("":"+r"(p):::foo);
>       foo:;
>       return p;
>   }
>
>
>
> -----
>
> Sorry, I think my original comment led you in the wrong direction.  Thinking about this a bit more, I think the solution is actually something like the following: treat any blockaddress passed to an "X" constraint the same way, regardless of whether there's a callbr involved, and regardless of the position in the input list.  I think that comes closest to matching the original design here.
>
> The "with an 'X' constraint" part avoids messing with users passing a blockaddress as a register input or something like that.
>
> Actually, not sure why clang is emitting "X" for asm goto destinations, instead of "i".  "i" is explicitly defined to be an immediate, and it's not clear what "X" is supposed to mean.  So maybe better to do something like the following:

`X` seems to be the correct constraint code to use:

  * i: An integer constant (of target-specific width). Allows either a simple immediate, or a relocatable value.
   ...
  * X: Allows an operand of any kind, no constraint whatsoever. Typically useful to pass a label for an asm branch or call.



> 1. Make clang emit "i" instead of "X" for asm goto destinations.  LLVM already handles blockaddress passed to "i" correctly.
> 2. Drop the special case for blockaddress in SelectionDAGBuilder::visitInlineAsm.
> 3. Optionally, add some extra handling for "X" in the backend, for backwards compatibility with IR generated by old clang.

We could possibly remove the special handling here. We just need to pass to `SelectionDAGBuilder::getValueImpl` something indicating that it's a "target".


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D114895/new/

https://reviews.llvm.org/D114895



More information about the llvm-commits mailing list