https://github.com/jayfoad created 
https://github.com/llvm/llvm-project/pull/242279

sext, zext and sext_inreg from i32 to i64 were selected to adds.w.sx or
adds.w.zx with an i32 result, followed by INSERT_SUBREG into an
IMPLICIT_DEF, which claims that the high 32 bits are undefined. These
instructions sign or zero extend the result into the whole 64-bit
register, so add codegen-only variants with i64 results and the same
encodings, and use them instead.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---

<sub>Stack created with <a href="https://github.com/github/gh-stack";>GitHub 
Stacks CLI</a> • <a href="https://gh.io/stacks-feedback";>Give Feedback 
💬</a></sub>

>From 57655c38042f02c506f40c7a5464e6e7e2bb9c93 Mon Sep 17 00:00:00 2001
From: Jay Foad <[email protected]>
Date: Fri, 13 Nov 2026 12:05:22 +0000
Subject: [PATCH] [VE] Define the whole register when extending i32 to i64.
 NFC.

sext, zext and sext_inreg from i32 to i64 were selected to adds.w.sx or
adds.w.zx with an i32 result, followed by INSERT_SUBREG into an
IMPLICIT_DEF, which claims that the high 32 bits are undefined. These
instructions sign or zero extend the result into the whole 64-bit
register, so add codegen-only variants with i64 results and the same
encodings, and use them instead.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
 llvm/lib/Target/VE/VEInstrInfo.td | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/llvm/lib/Target/VE/VEInstrInfo.td 
b/llvm/lib/Target/VE/VEInstrInfo.td
index 104c7714fb905..8ff7290d1e704 100644
--- a/llvm/lib/Target/VE/VEInstrInfo.td
+++ b/llvm/lib/Target/VE/VEInstrInfo.td
@@ -1217,6 +1217,15 @@ let cx = 1 in defm ADDUW : RRm<"addu.w", 0x48, I32, i32>;
 // Section 8.4.2 - ADS (Add Single)
 defm ADDSWSX : RRm<"adds.w.sx", 0x4A, I32, i32, add>;
 let cx = 1 in defm ADDSWZX : RRm<"adds.w.zx", 0x4A, I32, i32>;
+// adds.w.sx and adds.w.zx sign or zero extend the result into the whole 64-bit
+// register. These are used for extending i32 to i64.
+let isCodeGenOnly = 1, hasSideEffects = 0, cz = 0 in {
+def ADDSWSX64rm : RR<0x4A, (outs I64:$sx), (ins I32:$sy, mimm:$sz),
+                     "adds.w.sx $sx, $sy, $sz">;
+let cx = 1 in
+def ADDSWZX64rm : RR<0x4A, (outs I64:$sx), (ins I32:$sy, mimm:$sz),
+                     "adds.w.zx $sx, $sy, $sz">;
+}
 
 // Section 8.4.3 - ADX (Add)
 defm ADDSL : RRm<"adds.l", 0x59, I64, i64, add>;
@@ -1731,9 +1740,9 @@ def : Pat<(i32 (fp_to_sint f64:$src)), (CVTWDSXr RD_RZ, 
$src)>;
 def : Pat<(i32 (fp_to_sint f128:$src)), (CVTWDSXr RD_RZ, (CVTDQr $src))>;
 
 // Cast to i64
-def : Pat<(sext_inreg i64:$src, i32), (i2l (ADDSWSXrm (l2i $src), 0))>;
-def : Pat<(i64 (sext i32:$src)), (i2l (ADDSWSXrm $src, 0))>;
-def : Pat<(i64 (zext i32:$src)), (i2l (ADDSWZXrm $src, 0))>;
+def : Pat<(sext_inreg i64:$src, i32), (ADDSWSX64rm (l2i $src), 0)>;
+def : Pat<(i64 (sext i32:$src)), (ADDSWSX64rm $src, 0)>;
+def : Pat<(i64 (zext i32:$src)), (ADDSWZX64rm $src, 0)>;
 def : Pat<(i64 (anyext i32:$sy)), (i2l $sy)>;
 def : Pat<(i64 (fp_to_sint f32:$src)), (CVTLDr RD_RZ, (CVTDSr $src))>;
 def : Pat<(i64 (fp_to_sint f64:$src)), (CVTLDr RD_RZ, $src)>;

_______________________________________________
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits

Reply via email to