https://github.com/arsenm created https://github.com/llvm/llvm-project/pull/216696
Found by AI while working on something else. Co-authored-by: Claude (Opus 4.8) <[email protected]> >From 6c03d9831824ed9063b7c087bbfad8a3e9bd8242 Mon Sep 17 00:00:00 2001 From: Matt Arsenault <[email protected]> Date: Mon, 17 Aug 2026 13:04:54 +0200 Subject: [PATCH] PowerPC: Fix combineRLWINM crash on an undef folding operand Found by AI while working on something else. Co-authored-by: Claude (Opus 4.8) <[email protected]> --- llvm/lib/Target/PowerPC/PPCInstrInfo.cpp | 2 ++ llvm/test/CodeGen/PowerPC/fold-rlwinm.mir | 12 ++++++++++++ 2 files changed, 14 insertions(+) diff --git a/llvm/lib/Target/PowerPC/PPCInstrInfo.cpp b/llvm/lib/Target/PowerPC/PPCInstrInfo.cpp index d10e8b1c974f4..97a1d92e8bb1e 100644 --- a/llvm/lib/Target/PowerPC/PPCInstrInfo.cpp +++ b/llvm/lib/Target/PowerPC/PPCInstrInfo.cpp @@ -3892,6 +3892,8 @@ bool PPCInstrInfo::combineRLWINM(MachineInstr &MI, if (!FoldingReg.isVirtual()) return false; MachineInstr *SrcMI = MRI->getVRegDef(FoldingReg); + if (!SrcMI) + return false; if (SrcMI->getOpcode() != PPC::RLWINM && SrcMI->getOpcode() != PPC::RLWINM_rec && SrcMI->getOpcode() != PPC::RLWINM8 && diff --git a/llvm/test/CodeGen/PowerPC/fold-rlwinm.mir b/llvm/test/CodeGen/PowerPC/fold-rlwinm.mir index 729895efb11bb..759bccd24cc61 100644 --- a/llvm/test/CodeGen/PowerPC/fold-rlwinm.mir +++ b/llvm/test/CodeGen/PowerPC/fold-rlwinm.mir @@ -201,3 +201,15 @@ body: | %3:gprc = ANDI_rec %2:gprc, 4, implicit-def $cr0 BLR8 implicit $lr8, implicit $rm ... +--- +name: testFoldRLWINMUndef +tracksRegLiveness: true +body: | + bb.0.entry: + ; An undef folding operand has no def; combineRLWINM must not crash. + ; CHECK-LABEL: name: testFoldRLWINMUndef + ; CHECK: RLWINM undef %{{[0-9]+}}:gprc, 1, 0, 30 + %1:gprc = RLWINM undef %0:gprc, 1, 0, 30 + $r3 = COPY %1 + BLR implicit $lr, implicit $rm, implicit $r3 +... _______________________________________________ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
