diff --git a/llvm/lib/CodeGen/MachineSink.cpp b/llvm/lib/CodeGen/MachineSink.cpp --- a/llvm/lib/CodeGen/MachineSink.cpp +++ b/llvm/lib/CodeGen/MachineSink.cpp @@ -695,9 +695,10 @@ if (SuccToSinkTo) { // If a previous operand picked a block to sink to, then this operand // must be sinkable to the same block. - bool LocalUse = false; - if (!AllUsesDominatedByBlock(Reg, SuccToSinkTo, MBB, - BreakPHIEdge, LocalUse)) + bool LocalUse = false, PrevBreakPHIEdge = BreakPHIEdge; + if (!AllUsesDominatedByBlock(Reg, SuccToSinkTo, MBB, BreakPHIEdge, + LocalUse) || + BreakPHIEdge != PrevBreakPHIEdge) return nullptr; continue; diff --git a/llvm/test/CodeGen/PowerPC/pr45557.mir b/llvm/test/CodeGen/PowerPC/pr45557.mir new file mode 100644 --- /dev/null +++ b/llvm/test/CodeGen/PowerPC/pr45557.mir @@ -0,0 +1,32 @@ +# RUN: llc -mtriple=powerpc -verify-machineinstrs -simplify-mir \ +# RUN: --run-pass=machine-sink %s -o - | FileCheck %s + +--- | + @__const = external dso_local unnamed_addr constant [2 x i32], align 8 + define void @c() { + entry: + unreachable + } +... +--- +name: c +alignment: 4 +tracksRegLiveness: true +body: | + bb.0: + %3:gprc_and_gprc_nor0 = LIS target-flags(ppc-ha) @__const + %0:gprc, %4:gprc_and_gprc_nor0 = LWZU target-flags(ppc-lo) @__const, %3 :: (load 4 from `i64* bitcast ([2 x i32]* @__const to i64*)`, align 8) + %5:crbitrc = IMPLICIT_DEF + BC killed %5, %bb.2 + B %bb.1 + + bb.1: + %6:gprc = LI 0 + + bb.2: + %2:gprc = PHI %0, %bb.0, %6, %bb.1 + %1:gprc = LWZ 4, killed %4 :: (dereferenceable load 4 from `i64* bitcast ([2 x i32]* @__const to i64*)` + 4, align 8) + BLR implicit $lr, implicit $rm +... +# CHECK-LABEL: bb.2: +# CHECK-NOT: LWZU