[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
Fri Mar 22 14:49:02 PDT 2024


goldsteinn wrote:

> > > > This change looks fine, although it would be nice if we had some helper generically detecting if an op is reversable so we could generalize all these cases.
> > > 
> > > 
> > > Would also be useful for things like `icmp eq/ne X, C`
> > 
> > 
> > It has been supported.
> > https://github.com/llvm/llvm-project/blob/bbcfe6f4311af8cf6095a5bc5937fa68a87b4289/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp#L3621-L3633
> 
> Err I don't mean that to necessarily new support in `icmp eq/ne X, C` (or here for that matter). I mean we could use a common helper between `icmp eq/ne X, C` and here which would defintely add coverage to this function and at the very least reduce code duplication. I'm working on a patch.

See https://github.com/llvm/llvm-project/pull/86346 for what I mean.

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


More information about the llvm-commits mailing list