[PATCH] [llgo] irgen: generate switch instructions

Andrew Wilkins axwalk at gmail.com
Tue Jan 6 21:29:59 PST 2015


In http://reviews.llvm.org/D6831#105921, @pcc wrote:

> I wonder if there is a way to do this without modifying the go/ssa IR. In particular, I don't feel very comfortable about any attempt to define an instruction outside the ssa package. Maybe we can build a mapping to keep track of which ssa.If instructions are to be treated as switch instructions?


It is certainly possible to do that, and I did go down that road initially. I don't really like the kludginess of the current approach either, but the reason I did it this way was to keep it relatively self-contained. Aside from being (IMHO) a bit messy, adding a check to each "ssa.If" would mean we have a performance hit in the frontend for each If instruction, rather than just the ones that we care about. Maybe that's nothing to worry about; I haven't measured it.

I don't know if this will ever be necessary, but another option is for llgo to grow its own IR on top of go/ssa. I'd rather not go there for this, though.

> I believe LLVM already has a transformation to convert chains of branch instructions into switches, at least in some cases. Have you measured a performance improvement with this change at all? (Asking just out of curiosity. I think it would be worth exploring the performance impact of extending this to support type switches, so I have no objection to this change in principle.)


Geo-mean improvement of 0.49% (0.23% - 0.75% @ 95% CI)

There seems to be a fair bit of noise in some of the tests, since I'm getting supposed improvements in BenchmarkAppendGrowString, and BenchmarkTCP6ConcurrentReadWrite. One significant improvement that looks genuine is:

  BenchmarkCSSEscaper 2983.000000 2476.000000 1.204766

Standard optimisations do not appear to convert branches to switches AFAICT, but perhaps I'm doing something wrong. I did look to see if there was an existing pass, but again I couldn't see anything that looked relevant. There is a pass that goes the opposite direction, converting switches to branches, for targets that don't implement switch.


REPOSITORY
  rL LLVM

http://reviews.llvm.org/D6831

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/






More information about the llvm-commits mailing list