[PATCH] D99884: [LV] Logical and/or select costs

Dave Green via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 6 02:43:23 PDT 2021


dmgreen added inline comments.


================
Comment at: llvm/lib/Transforms/Vectorize/LoopVectorize.cpp:7445
+    if (!ScalarCond && (match(I, m_LogicalAnd(m_Value(Op0), m_Value(Op1))) ||
+                        match(I, m_LogicalOr(m_Value(Op0), m_Value(Op1))))) {
+      // select x, y, false --> x & y
----------------
aqjune wrote:
> If the select is loop invariant, it is still considered expensive - is there a reason why it is so?
That would become a `%a5 = select i1 %c, <4 x i1> <i1 1, i1 1, i1 1, i1 1>, <4 x i1> %a4`
Which I don't think would then be converted to an and/or

At least under MVE, it becomes a branch, as that is how we lower vector SELECTs (as opposed to VSELECT, which are lowered to an MVE instruction using the predicate register).
https://godbolt.org/z/ecev1KcKe
Which can end up in the loop:
https://godbolt.org/z/6abW4M5vn
```
.LBB0_8:
        vmsr    p0, r5
.LBB0_9:
        vldrw.u32       q1, [r4], #16
        adds    r6, #16
        vpsel   q0, q0, q1
        vstrb.8 q0, [r9], #16
        subs.w  lr, lr, #1
        bne     .LBB0_10
        b       .LBB0_12
.LBB0_10:
        vldrw.u32       q0, [r6]
        cmp.w   r12, #0
        ble     .LBB0_8
        vcmp.s32        gt, q0, zr
        b       ,LBB0_9
```


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D99884/new/

https://reviews.llvm.org/D99884



More information about the llvm-commits mailing list