[llvm] [DAG] Generalize setcc(setcc) fold to use known bits. (PR #66503)
David Green via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 19 03:53:39 PDT 2023
================
@@ -403,14 +403,19 @@ define i32 @PR17487(i1 %tobool) {
;
; X64-LIN-LABEL: PR17487:
; X64-LIN: # %bb.0:
-; X64-LIN-NEXT: movl %edi, %eax
-; X64-LIN-NEXT: andl $1, %eax
+; X64-LIN-NEXT: movd %edi, %xmm0
+; X64-LIN-NEXT: pshufd {{.*#+}} xmm0 = xmm0[0,1,0,1]
+; X64-LIN-NEXT: pand {{\.?LCPI[0-9]+_[0-9]+}}(%rip), %xmm0
+; X64-LIN-NEXT: pextrw $4, %xmm0, %eax
; X64-LIN-NEXT: retq
;
; X64-WIN-LABEL: PR17487:
; X64-WIN: # %bb.0:
-; X64-WIN-NEXT: andb $1, %cl
; X64-WIN-NEXT: movzbl %cl, %eax
+; X64-WIN-NEXT: movd %eax, %xmm0
+; X64-WIN-NEXT: pshufd {{.*#+}} xmm0 = xmm0[0,1,0,1]
+; X64-WIN-NEXT: pand __xmm at 00000000000000010000000000000001(%rip), %xmm0
+; X64-WIN-NEXT: pextrw $4, %xmm0, %eax
----------------
davemgreen wrote:
Yeah these I wasn't sure about - how important they were. They get folded away under normal optimizations: https://godbolt.org/z/P4vMYd5oc, and it looked like the test was only added for correctness.
I think if the combines happened in topo order it might do better. The DAG looks like this:
```
t56: v4i32 = BUILD_VECTOR undef:i32, undef:i32, t2, undef:i32
t57: v2i64 = bitcast t56
t36: v2i64 = BUILD_VECTOR Constant:i64<1>, Constant:i64<1>
t39: v2i64 = and t57, t36
t50: v16i8 = bitcast t39
t51: i8 = extract_vector_elt t50, Constant:i64<8>
t45: i32 = zero_extend t51
```
https://github.com/llvm/llvm-project/pull/66503
More information about the llvm-commits
mailing list