[llvm] [InstCombine] Lower flag check pattern to use a bitmask-shift (PR #169557)
Ryan Buchner via llvm-commits
llvm-commits at lists.llvm.org
Mon Dec 1 19:14:29 PST 2025
bababuck wrote:
Updated the PR description.
```
bool or_icmp(int type) {
return (type == 0 || type == 6 || type == 15);
}
```
is converted to an IR switch statement during SimplifyCFG, which SimplifyCFG then transforms into a bitmask-shift, while
```
bool or_icmp(int type) {
if (type == 0 || type == 6 || type == 15)
return true;
return false;
}
```
is not optimally lowered and is addressed by this MR (see https://compiler-explorer.com/z/9P7P7bj5r). From browsing, I don't think fixing this in `SimplifyCFG` is the best solution since this pattern can exist inside a single basic block (i.e. :
```
%cmp = icmp eq i32 %type, 0
%cmp1 = icmp eq i32 %type, 6
%or.cond = or i1 %cmp, %cmp1
%cmp3 = icmp eq i32 %type, 15
%or.cond4 = or i1 %or.cond, %cmp3
ret i1 %or.cond4
```
https://github.com/llvm/llvm-project/pull/169557
More information about the llvm-commits
mailing list