llvm / llvm/llvm-project

Missed optimization: simplify splat-vector bitcast to scalar multiplication/masking

Open
#185,694 3 comments 0 reactions 1 assignee Claimed by @Camsyn View on GitHub
llvm:optimizations missed-optimization
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

```llvm
define i32 @src(i64 %arg0, i64 %arg1) {
%v0 = icmp eq i64 %arg1, %arg0
%v1 = insertelement <4 x i1> poison, i1 %v0, i64 0
%v2 = shufflevector <4 x i1> %v1, <4 x i1> poison, <4 x i32> zeroinitializer
%v3 = bitcast <4 x i1> %v2 to i4
%v4 = zext i4 %v3 to i32
ret i32 %v4
}

define i32 @tgt(i64 %arg0, i64 %arg1) {
%v0 = icmp eq i64 %arg1, %arg0
%v_i32 = zext i1 %v0 to i32
%result = mul i32 %v_i32, 15
ret i32 %result
}
```

alive2: https://alive2.llvm.org/ce/z/uUn2VN
godbolt: https://godbolt.org/z/3q3fxdYzK
Pattern found in: https://github.com/dtcxzyw/llvm-opt-benchmark/blob/main/bench/velox/optimized/Comparisons.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.