mbox series

[0/4] simplification of computed goto

Message ID 20201121205300.94642-1-luc.vanoostenryck@gmail.com (mailing list archive)
Headers show
Series simplification of computed goto | expand

Message

Luc Van Oostenryck Nov. 21, 2020, 8:52 p.m. UTC
This series contains some simplification of computed gotos with
1 or 2 possible target as well as a new instruction which now
really allows the CSE of 'labels-as-values'.

Luc Van Oostenryck (4):
  add testcases for COMPUTEDGOTO simplification
  simplify OP_COMPUTEDGOTO with unique and known target
  simplify CGOTO(SEL(x, L1, L2)) into CBR x, L1, L2
  add a new instruction for label-as-value

 cse.c                        |  9 +++++
 example.c                    |  8 +++--
 linearize.c                  |  6 ++++
 liveness.c                   |  1 +
 opcode.def                   |  1 +
 simplify.c                   | 68 ++++++++++++++++++++++++++++++++++--
 sparse-llvm.c                | 11 ++++++
 validation/optim/cgoto01.c   | 24 +++++++++++++
 validation/optim/cgoto02.c   | 17 +++++++++
 validation/optim/cse-label.c | 13 +++++++
 10 files changed, 153 insertions(+), 5 deletions(-)
 create mode 100644 validation/optim/cgoto01.c
 create mode 100644 validation/optim/cgoto02.c
 create mode 100644 validation/optim/cse-label.c

Comments

Linus Torvalds Nov. 21, 2020, 9:09 p.m. UTC | #1
On Sat, Nov 21, 2020 at 12:54 PM Luc Van Oostenryck
<luc.vanoostenryck@gmail.com> wrote:
>
> This series contains some simplification of computed gotos with
> 1 or 2 possible target as well as a new instruction which now
> really allows the CSE of 'labels-as-values'.

Looks sane, but where did you actually find cases of this in real life?

I think we have one computed goto in the kernel, that does an array
label load. They are very rare, and when they are used, that tends to
be the normal pattern.

Just about the only place I've ever seen them are in that kind of
interpreter loops for instruction dispatch tables.

          Linus
Luc Van Oostenryck Nov. 21, 2020, 9:40 p.m. UTC | #2
On Sat, Nov 21, 2020 at 01:09:50PM -0800, Linus Torvalds wrote:
> On Sat, Nov 21, 2020 at 12:54 PM Luc Van Oostenryck
> <luc.vanoostenryck@gmail.com> wrote:
> >
> > This series contains some simplification of computed gotos with
> > 1 or 2 possible target as well as a new instruction which now
> > really allows the CSE of 'labels-as-values'.
> 
> Looks sane, but where did you actually find cases of this in real life?
>
> I think we have one computed goto in the kernel, that does an array
> label load. They are very rare, and when they are used, that tends to
> be the normal pattern.
> 

Bah, they're not really from real life.
When IR and optimizations are concerned, I'm using code from some
testsuites (GCC, LLVM, some benchmarks, code I've generated myself)
to check for anything abnormal and sometimes when inspecting the
results I fall on some testcases that doesn't make sense. Sometimes
it's because of some errors from my part but it also happens it's
one of these silly/exotic transformations.

So, yes, I'm fully aware that these patches (and some other
'optimizations' I'm sometimes adding) have practically no values
but they just make things easier for me when comparing results.

> Just about the only place I've ever seen them are in that kind of
> interpreter loops for instruction dispatch tables.

Yes. They were also fundamental to a prolog-to-C compiler I wrote
many years ago. This maybe explains some fondness I've for them.

-- Luc
Linus Torvalds Nov. 21, 2020, 10:07 p.m. UTC | #3
On Sat, Nov 21, 2020 at 1:40 PM Luc Van Oostenryck
<luc.vanoostenryck@gmail.com> wrote:
>
> Bah, they're not really from real life.

Ok, I was worried I was missing something, and you'd find some really
odd kernel code ;)

             Linus