From: Richard Earnshaw <[email protected]>

gen_highpart will abort if the operand is a subreg; avoid this by copying
the operands to/from temporary registers.

gcc/ChangeLog:

        PR target/127393
        * config/aarch64/aarch64.md (negvti3): Ensure the operands are
        not subregs; use temporaries if needed.
---
This is a forge pull request published on the gcc-patches mailing list mailing 
list
as requested by Richard Earnshaw via Sourceware Forge 
<[email protected]>.
Forge discussion: https://forge.sourceware.org/gcc/gcc/pulls/231

Get it locally using:
```
git fetch forge-upstream "+refs/versioned_pull/231/*:refs/versioned_pull/231/*"
git switch -c "pr-231-v1" "refs/versioned_pull/231/1/head"
```
Or, download the patch at: https://forge.sourceware.org/gcc/gcc/pulls/231.diff
Created on: 2026-09-16 14:22:10+00:00
Latest update: 2026-09-16 14:22:11+00:00
Changes: 1 changed files, 13 additions, 4 deletions
Head revision: rearnsha/gcc ref negvti3_subreg commit 
a119588e63793ca6a6f4933e6aa3046ad833da0f 
Base revision: gcc/gcc ref trunk commit 
05c3df2b98e66011ba4c5b070d2d755d4d548297 r17-4368-g05c3df2b98e660
Merge base: 05c3df2b98e66011ba4c5b070d2d755d4d548297
Requested Reviewers: 

Changed files:
- M: gcc/config/aarch64/aarch64.md

 gcc/config/aarch64/aarch64.md | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/gcc/config/aarch64/aarch64.md b/gcc/config/aarch64/aarch64.md
index 302658c970d27..22c688d2c39e6 100644
--- a/gcc/config/aarch64/aarch64.md
+++ b/gcc/config/aarch64/aarch64.md
@@ -3761,10 +3761,19 @@
    (label_ref (match_operand 2 "" ""))]
   ""
   {
-    emit_insn (gen_negdi_carryout (gen_lowpart (DImode, operands[0]),
-                                  gen_lowpart (DImode, operands[1])));
-    emit_insn (gen_negvdi_carryinV (gen_highpart (DImode, operands[0]),
-                                   gen_highpart (DImode, operands[1])));
+    rtx in = operands[1];
+    rtx out = operands[0];
+    if (!REG_P (in))
+      in = force_reg (TImode, in);
+    if (!REG_P (out))
+      out = gen_reg_rtx (TImode);
+
+    emit_insn (gen_negdi_carryout (gen_lowpart (DImode, out),
+                                  gen_lowpart (DImode, in)));
+    emit_insn (gen_negvdi_carryinV (gen_highpart (DImode, out),
+                                   gen_highpart (DImode, in)));
+    if (out != operands[0])
+      emit_insn (gen_movti (operands[0], out));
     aarch64_gen_unlikely_cbranch (NE, CC_Vmode, operands[2]);
 
     DONE;
-- 
2.54.0

Reply via email to