[llvm] [InstCombine] Fold `switch(rol(x, C1)) case C2:` to `switch(x) case rol(C2, -C1):` (PR #86307)

via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 10 05:28:49 PDT 2024


YanWQ-monad wrote:

> I don't really like the idea of SimplifyCFG and InstCombine changing the code back and forth. Maybe we should limit the fold to the case where it will not make the switch less dense?

It's rare that the fold will make the switch dense, at least as the issue shows, and in dtcxzyw's benchmark. So a more reasonable solution should be limit the fold so that it won't affect `ReduceSwitchRange`?

If so, `isSwitchDense` may be needed to check the preconditions, but it's only visible inside SimplifyCFG. Should I place `isSwitchDense` to somewhere else to make it shared between SimplifyCFG and InstCombine?

https://github.com/llvm/llvm-project/pull/86307


More information about the llvm-commits mailing list