https://gcc.gnu.org/g:4528bf93ee7362cc5dba0ab973de1ef38571a2e1

commit r17-6684-g4528bf93ee7362cc5dba0ab973de1ef38571a2e1
Author: Jakub Jelinek <[email protected]>
Date:   Wed Nov 25 13:04:33 2026 +0100

    aarch64: Fix ICE on TImode comparison of a SUBREG [PR128762]
    
    The following testcase ICEs, because aarch64_gen_compare_reg for TImode
    uses operand_subword to get the two halves of each operand.  If one
    or both operands are SUBREGs, especially the second calls to
    operand_subword, the one asking for the high half, can just return NULL_RTX
    because they try to simplify_gen_subreg and SUBREGs of SUBREGs aren't
    supported.
    The following patch fixes it by using force_{low,high}part_subreg instead
    of operand_subword.
    
    2026-11-25  Jakub Jelinek  <[email protected]>
                Tamar Christina  <[email protected]>
    
            PR target/128762
            * config/aarch64/aarch64.cc (aarch64_gen_compare_reg): Use
            force_lowpart_subreg/force_highpart_subreg instead of 
operand_subword.
    
            * gcc.dg/pr128762.c: New test.
    
    Reviewed-by: Tamar Christina <[email protected]>
    Reviewed-by: Kyrylo Tkachov <[email protected]>

Diff:
---
 gcc/config/aarch64/aarch64.cc   |  8 ++++----
 gcc/testsuite/gcc.dg/pr128762.c | 13 +++++++++++++
 2 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/gcc/config/aarch64/aarch64.cc b/gcc/config/aarch64/aarch64.cc
index 98f4f88deada..dd24d3b669fe 100644
--- a/gcc/config/aarch64/aarch64.cc
+++ b/gcc/config/aarch64/aarch64.cc
@@ -3218,12 +3218,12 @@ aarch64_gen_compare_reg (RTX_CODE code, rtx x, rtx y)
       cc_mode = CCmode;
       cc_reg = gen_rtx_REG (cc_mode, CC_REGNUM);
 
-      rtx x_lo = operand_subword (x, 0, 0, TImode);
-      rtx y_lo = operand_subword (y, 0, 0, TImode);
+      rtx x_lo = force_lowpart_subreg (DImode, x, TImode);
+      rtx y_lo = force_lowpart_subreg (DImode, y, TImode);
       emit_set_insn (cc_reg, gen_rtx_COMPARE (cc_mode, x_lo, y_lo));
 
-      rtx x_hi = operand_subword (x, 1, 0, TImode);
-      rtx y_hi = operand_subword (y, 1, 0, TImode);
+      rtx x_hi = force_highpart_subreg (DImode, x, TImode);
+      rtx y_hi = force_highpart_subreg (DImode, y, TImode);
       emit_insn (gen_ccmpccdi (cc_reg, cc_reg, x_hi, y_hi,
                               gen_rtx_EQ (cc_mode, cc_reg, const0_rtx),
                               GEN_INT (AARCH64_EQ)));
diff --git a/gcc/testsuite/gcc.dg/pr128762.c b/gcc/testsuite/gcc.dg/pr128762.c
new file mode 100644
index 000000000000..dc7e72e74f1e
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr128762.c
@@ -0,0 +1,13 @@
+/* PR target/128762 */
+/* { dg-do compile { target int128 } } */
+/* { dg-options "-O2" } */
+
+__attribute__((__vector_size__(16))) short v;
+__int128 x;
+short s;
+
+void
+foo (void)
+{
+  __sync_bool_compare_and_swap (&x, v + s, 0);
+}

Reply via email to