Skip to content

[InstCombine] Preferred shift direction in bit test #41811

@LebedevRI

Description

@LebedevRI
Bugzilla Link 42466
Version trunk
OS Linux
CC @topperc,@davidbolvansky,@efriedma-quic,@RKSimon,@nikic,@rotateright

Extended Description

As discussed in https://reviews.llvm.org/D63829

These two patterns are identical:

define i1 @​v0(i32 %x, i32 %y, i32 %z) {
%t0 = lshr i32 %x, %y
%t2 = and i32 %t0, %z
%t3 = icmp ne i32 %t2, 0
ret i1 %t3
}
define i1 @​v1(i32 %x, i32 %y, i32 %z) {
%t0 = shl i32 %y, %y
%t2 = and i32 %t0, %x
%t3 = icmp ne i32 %t2, 0
ret i1 %t3
}

We should canonicalize to one of them.
Probably to @​v0.
With one obvious exception of (1 << y) & x.

https://godbolt.org/z/KPgPPQ
https://rise4fun.com/Alive/0avd

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugzillaIssues migrated from bugzillallvm:instcombineCovers the InstCombine, InstSimplify and AggressiveInstCombine passes

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions