[llvm-dev] Branch is not optimized because of right shift

Florian Hahn via llvm-dev llvm-dev at lists.llvm.org
Sun Apr 5 14:38:10 PDT 2020



> On Apr 5, 2020, at 22:20, Stefanos Baziotis <stefanos.baziotis at gmail.com> wrote:
> 
> > Any idea about how the compiler could remove the lshr and use a add -16?
> Actually, I just figured that doing this test is like solving this:
> 
> 8 <= x/2 <= 13
> 16 <= x <= 26
> 0 <= x - 16 <= 10 => 0 <= x < 11
> The left part is know since it's unsigned
> The right part could be done x <= 11 => x < 12 because it's actually an integer division.
> Wow... I would be really happy to know what pass does that.

I’d guess a combination of instcombine rules together with some other transforms. You could probably use `-print-after-all` (`clang -mllvm -print-after-all` if you are using clang) to track down the relevant passes/steps.


More information about the llvm-dev mailing list