llvm / llvm/llvm-project

Missed Optimization: Fold parity select (x&1 ? (x-1): (x|1) ) into x ^ 1

Open
#167,173 1 comment 0 reactions 0 assignees View on GitHub
llvm:instcombine missed-optimization
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

```
define i32 @src(i32 %arg0) {
%v0 = and i32 %arg0, 1
%v1 = icmp eq i32 %v0, 0
%v2 = or disjoint i32 %arg0, 1
%v3 = add nsw i32 %arg0, -1
%v4 = select i1 %v1, i32 %v2, i32 %v3
%v5 = srem i32 %v4, 6
ret i32 %v5
}

define i32 @tgt(i32 %arg0) {
%v4_opt = xor i32 %arg0, 1
%v5_opt = srem i32 %v4_opt, 6
ret i32 %v5_opt
}
```
alive2: https://alive2.llvm.org/ce/z/VGsqMZ
godbolt: https://godbolt.org/z/zETszvo4o
Pattern found in: https://github.com/dtcxzyw/llvm-opt-benchmark/blob/main/bench/linux/optimized/uncore_nhmex.ll

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.