[PATCH] D144927: [GVNHoist] don't hoist callbr users into the callbr's block

Nick Desaulniers via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 9 10:13:05 PST 2023


nickdesaulniers planned changes to this revision.
nickdesaulniers marked an inline comment as done.
nickdesaulniers added inline comments.


================
Comment at: llvm/lib/Transforms/Scalar/GVNHoist.cpp:819
+    // the use above the def.
+    if (is_contained(T->users(), Insn))
+      continue;
----------------
nikic wrote:
> nickdesaulniers wrote:
> > hiraditya wrote:
> > > hiraditya wrote:
> > > > I'm assuming there are only a few `T->users` in practice, otherwise linear search on users could be slow.
> > > maybe we can check if `Insn` has any operands that are defined by `T`
> > > I'm assuming there are only a few T->users in practice
> > 
> > In practice, only `CallBrInst`'s are terminators that produce values/can even have users.  In practice, the number of users is 1.
> > 
> > > maybe we can check if Insn has any operands that are defined by T
> > 
> > Equivalent.
> > In practice, only CallBrInst's are terminators that produce values/can even have users.
> 
> Invokes also produces values and have users. Though it's possible that those aren't supported by GVNHoist.
> 
> > In practice, the number of users is 1.
> 
> Hm, why? I'd expect more than one users even for front-end generated IR, depending on number of return values and number of control-flow paths.
> Invokes also produces values and have users.

I guess `catchswitch` would be, too. I'll update the comment.

> Hm, why? I'd expect more than one users even for front-end generated IR, depending on number of return values and number of control-flow paths.

The common case of `callbr`'s produced-value usage comes from `asm goto ("":"=r"(x):::foo); return x; bar: return 42;`.

It is technically possible for the usage of the value to be 0 (unused) to many (used along every label in the label list).  In practice, the number of users is 1.

Even if it's many, a linear search for any small number of N is irrelevant.  I could make the same claim that a linear search through the operands of an instruction might be slow, for an instruction with infinite operands. Do any such instructions exist? Does it matter?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144927



More information about the llvm-commits mailing list