Open Validark opened 2 months ago
@llvm/issue-subscribers-backend-x86
Author: Niles Salter (Validark)
MachineLICM is not applied currently because the instruction depends on a PHI
node (%v2
) defined inside the loop.
; predecessors: %bb.0, %bb.1
successors: %bb.2(0x04000000), %bb.1(0x7c000000); %bb.2(3.12%), %bb.1(96.88%)
%1:gr64 = PHI %0:gr64, %bb.0, %4:gr64, %bb.1
%2:vr512 = PHI %6:vr512, %bb.0, %3:vr512, %bb.1
%7:vr512 = VMOVDQA64Zrm %1:gr64, 1, $noreg, -64, $noreg :: (load (s512) from %ir.scevgep6)
%8:vk64wm = VPCMPBZrri killed %7:vr512, %9:vr512, 0
%3:vr512 = VMOVDQU8Zrmk %2:vr512(tied-def 0), killed %8:vk64wm, $rip, 1, $noreg, %const.1, $noreg :: (load (s512) from constant-pool)
%4:gr64 = ADD64ri32 %1:gr64(tied-def 0), 64, implicit-def dead $eflags
CMP8mi %1:gr64, 1, $noreg, 0, $noreg, 0, implicit-def $eflags :: (load (s8) from %ir.lsr.iv, align 64)
JCC_1 %bb.1, 5, implicit $eflags
JMP_1 %bb.2
Its simpler than that - we don't allow unfolding VMOVDQU8Zrmk instructions back to VMOVDQU8Zrrk to prevent illegal memory access (bounded by the predicate mask).
{X86::VMOVDQU8Zrrk, X86::VMOVDQU8Zrmk, TB_NO_REVERSE},
@KanRobert how easy would it be to safely allow constant pool loads to be unfolded?
I have real code using a
@select
statement in Zig like so:Zen 4 emit:
Zig godbolt link
In my opinion, it should be:
Here is the LLVM IR emitted by Zig:
(I ran
zig build-obj ./src/llvmbadloop.zig -O ReleaseFast -target x86_64-linux -mcpu znver4 -femit-llvm-ir -fstrip
, then erased the unnecessarytarget triple
and other config stuff)LLVM IR dump Godbolt link