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

Eli Friedman via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 7 14:57:08 PST 2021


efriedma added a comment.

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:

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.


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