[llvm] [PowerPC] Fix wrteei crash: use u1imm instead of i1imm (PR #188558)

via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 26 11:07:22 PDT 2026


https://github.com/Scottcjn updated https://github.com/llvm/llvm-project/pull/188558

>From dbf238479b8dd1609dcbf864f092e68e1e0b0263 Mon Sep 17 00:00:00 2001
From: Scott Boudreaux <scottbphone12 at gmail.com>
Date: Fri, 15 May 2026 11:51:07 -0500
Subject: [PATCH] [PowerPC] Fix wrteei crash: use u1imm instead of i1imm

wrteei uses i1imm (generic Operand<i1> with no ParserMatchClass)
which allows register names like f0, r0, cr0 to be accepted as
the enable-bit operand. In debug builds this crashes with an
assertion in PPCMCCodeEmitter::getMachineOpValue(); in release
builds it silently emits wrong encoding.

Fix by changing the operand type from i1imm to u1imm, which has
PPCU1ImmAsmOperand as its ParserMatchClass with the isU1Imm
predicate that validates the operand is a numeric immediate in
range [0, 1]. This matches RFEBB which already uses u1imm for
its 1-bit immediate operand.

Fixes #185359.
---
 llvm/lib/Target/PowerPC/PPCInstrInfo.td    |  2 +-
 llvm/test/MC/PowerPC/ppc-wrteei-validate.s | 28 ++++++++++++++++++++++
 2 files changed, 29 insertions(+), 1 deletion(-)
 create mode 100644 llvm/test/MC/PowerPC/ppc-wrteei-validate.s

diff --git a/llvm/lib/Target/PowerPC/PPCInstrInfo.td b/llvm/lib/Target/PowerPC/PPCInstrInfo.td
index a67da9b85aa94..83641b4f64cd7 100644
--- a/llvm/lib/Target/PowerPC/PPCInstrInfo.td
+++ b/llvm/lib/Target/PowerPC/PPCInstrInfo.td
@@ -4539,7 +4539,7 @@ def WRTEE: XForm_mtmsr<31, 131, (outs), (ins gprc:$RS),
   let L = 0;
 }
 
-def WRTEEI: I<31, (outs), (ins i1imm:$E), "wrteei $E", IIC_SprMTMSR>,
+def WRTEEI: I<31, (outs), (ins u1imm:$E), "wrteei $E", IIC_SprMTMSR>,
               Requires<[IsBookE]> {
   bits<1> E;
 
diff --git a/llvm/test/MC/PowerPC/ppc-wrteei-validate.s b/llvm/test/MC/PowerPC/ppc-wrteei-validate.s
new file mode 100644
index 0000000000000..127ddc9828875
--- /dev/null
+++ b/llvm/test/MC/PowerPC/ppc-wrteei-validate.s
@@ -0,0 +1,28 @@
+# RUN: llvm-mc -triple powerpc64-unknown-linux-gnu -show-encoding %s 2>&1 | \
+# RUN:   FileCheck %s
+
+# RUN: not llvm-mc -triple powerpc64-unknown-linux-gnu %s --defsym=ERR=1 2>&1 | \
+# RUN:   FileCheck %s --check-prefix=CHECK-ERR
+
+# Valid wrteei operands (0 and 1)
+wrteei 0
+# CHECK: wrteei 0
+wrteei 1
+# CHECK: wrteei 1
+
+.ifdef ERR
+# Invalid: register names should be rejected as immediate operands
+wrteei f0
+# CHECK-ERR: [[@LINE-1]]:{{[0-9]+}}: error:
+wrteei r0
+# CHECK-ERR: [[@LINE-1]]:{{[0-9]+}}: error:
+wrteei cr0
+# CHECK-ERR: [[@LINE-1]]:{{[0-9]+}}: error:
+wrteei v0
+# CHECK-ERR: [[@LINE-1]]:{{[0-9]+}}: error:
+# Invalid: out of range
+wrteei 2
+# CHECK-ERR: [[@LINE-1]]:{{[0-9]+}}: error:
+wrteei -1
+# CHECK-ERR: [[@LINE-1]]:{{[0-9]+}}: error:
+.endif



More information about the llvm-commits mailing list