[llvm] [MachineCSE] Walk the terminator the hoisted copy is placed in front of (PR #215158)
Matt Turner via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 2 05:28:40 PDT 2026
================
@@ -0,0 +1,62 @@
+# RUN: llc -mtriple=x86_64-unknown-linux-gnu -run-pass=machine-cse -verify-machineinstrs -o - %s | FileCheck %s
+
+# Partial redundancy elimination hoists a computation into the nearest common
+# dominator of the two blocks holding it, in front of that block's first
+# terminator. A computation that reads a physical register may only be hoisted
+# if the register still holds the same value where the copy lands, and the walk
+# that checks that has to start at the terminator rather than after it: the copy
+# goes in front of the terminator, so whatever the terminator clobbers lies
+# between the copy and the original.
+#
+# EH_SjLj_Setup is such a terminator. It carries a register mask preserving
+# nothing, which is what keeps a value from staying in a register across a
+# setjmp, and it names the block a returning longjmp resumes at, so its block
+# has a fallthrough successor as well. The rip-relative lea below must not be
+# hoisted in front of it.
+
+--- |
+ define i64 @foo() {
+ entry:
+ br i1 poison, label %setjmp, label %land
+ setjmp:
+ br label %join
+ land:
+ br label %join
+ join:
+ ret i64 0
+ }
+...
+---
+name: foo
+tracksRegLiveness: true
+body: |
+ bb.0.entry:
+ successors: %bb.1(0x40000000), %bb.3(0x40000000)
+
+ EH_SjLj_Setup %bb.3, csr_noregs
+
+ bb.1.setjmp:
+ successors: %bb.2(0x80000000)
+
+ %0:gr64 = LEA64r $rip, 1, $noreg, 0, $noreg
+
+ bb.2.join:
+ %2:gr64 = PHI %0, %bb.1, %1, %bb.3
+ %3:gr64 = LEA64r $rip, 1, $noreg, 0, $noreg
+ %4:gr64 = ADD64rr %2, %3, implicit-def dead $eflags
+ $rax = COPY %4
+ RET64 implicit $rax
+
+ bb.3.land (machine-block-address-taken):
+ successors: %bb.2(0x80000000)
+
+ %1:gr64 = LEA64r $rip, 1, $noreg, 8, $noreg
+ JMP_1 %bb.2
+...
+
+# CHECK-LABEL: name: foo
+# CHECK: bb.0.entry:
+# CHECK-NOT: LEA64r
----------------
mattst88 wrote:
Done, thanks.
https://github.com/llvm/llvm-project/pull/215158
More information about the llvm-commits
mailing list