[llvm-bugs] [Bug 46756] New: Is it intended behaviour for LLVM to emit `vpbroadcastd` for a constant on every iteration.

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Jul 16 16:32:24 PDT 2020


https://bugs.llvm.org/show_bug.cgi?id=46756

            Bug ID: 46756
           Summary: Is it intended behaviour for LLVM to emit
                    `vpbroadcastd` for a constant on every iteration.
           Product: clang
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: -New Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: denis.yaroshevskij at gmail.com
                CC: htmldeveloper at gmail.com, llvm-bugs at lists.llvm.org,
                    neeilans at live.com, richard-llvm at metafoo.co.uk

This is the main loop:

```
.LBB0_8:                                #   Parent Loop BB0_6 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
        vmovdqa ymm7, ymmword ptr [rdi]
        vpcmpgtd        ymm8, ymm2, ymm7
        vpminsd ymm2, ymm2, ymm7
        vpblendvb       ymm1, ymm1, ymm6, ymm8
        vpbroadcastd    ymm7, dword ptr [rip + .LCPI0_2] # ymm7 =
[8,8,8,8,8,8,8,8]
        vpaddd  ymm6, ymm6, ymm7
        add     rdi, 32
        cmp     rcx, rdi
        jne     .LBB0_8
```

This `vpbroadcastd` that just assigns 8 on every step seems like a bug.
In a similar situation llvm keeps it in the register, see
https://gcc.godbolt.org/z/94M91c for both unrolled and not unrolled cases.

Profiling is inconclusive in terms of if this `broadcast` is a problem:

 0.11  │       data16       data16 data16 data16 nop WORD PTR
cs:[rax+rax*1+0x0]
 0.88  │       vmovdqa      ymm8,YMMWORD PTR [rdi]
 0.27  │       vpcmpgtd     ymm9,ymm5,ymm8
 27.13 │       vpminsd      ymm5,ymm5,ymm8
 30.93 │       vpblendvb    ymm4,ymm4,ymm7,ymm9
       │       vpbroadcastd ymm8,DWORD PTR [rip+0x9974b]

My code you won't be able to compile, but here is a complete disassembly:
https://github.com/DenisYaroshevskiy/unsq_eve/blob/8dc8e992d9ced36c0a37b8ea6a6ae3eb6e97d6e2/disassemble/disassemble.s#L118

Is this expected? If it's not - can you recommend a workaround?

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20200716/031312a1/attachment.html>


More information about the llvm-bugs mailing list