Issue 172888
Summary [InstCombine] Missed icmp_ne(and(x,1),0) -> trunc(x) fold
Labels llvm:instcombine, missed-optimization
Assignees
Reporter RKSimon
    https://alive2.llvm.org/ce/z/U5bXFr
```ll
----------------------------------------
define i1 @src(i32 %a2) {
  %s2 = and i32 %a2, 1
  %t2 = icmp ne i32 %s2, 0
  ret i1 %t2
}
=>
define i1 @tgt(i32 %a2) {
  %t2 = trunc i32 %a2 to i1
  ret i1 %t2
}
Transformation seems to be correct!
```
Noticed while working on vector code trying to fold SSE/AVX blendv intrinsics to generic select ops:
```ll
define <8 x float> @src(<8 x float> %a0, <8 x float> %a1, <8 x i32> %a2) {
  %s2 = shl <8 x i32> %a2, splat (i32 31)
  %c2 = icmp slt <8 x i32> %s2, zeroinitializer
  %r = select <8 x i1> %c2, <8 x float> %a0, <8 x float> %a1
  ret <8 x float> %r
}
define <8 x float> @tgt(<8 x float> %a0, <8 x float> %a1, <8 x i32> %a2) {
  %t2 = trunc <8 x i32> %a2 to <8 x i1>
 %r = select <8 x i1> %t2, <8 x float> %a0, <8 x float> %a1
  ret <8 x float> %r
}
```
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to