From 167ef0417008ac6fce811cc077afa116ecda395e Mon Sep 17 00:00:00 2001 From: Pavol Rusnak Date: Sun, 13 Apr 2025 14:34:48 +0200 Subject: [PATCH] gcc14: fix internal compiler error on aarch64 - https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118501 - https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118892 - https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119133 --- .../patches/14/aarch64-fix-ice-subreg.patch | 87 +++++++++++++++++++ .../compilers/gcc/patches/default.nix | 5 ++ 2 files changed, 92 insertions(+) create mode 100644 pkgs/development/compilers/gcc/patches/14/aarch64-fix-ice-subreg.patch diff --git a/pkgs/development/compilers/gcc/patches/14/aarch64-fix-ice-subreg.patch b/pkgs/development/compilers/gcc/patches/14/aarch64-fix-ice-subreg.patch new file mode 100644 index 000000000000..a8783ddbfa27 --- /dev/null +++ b/pkgs/development/compilers/gcc/patches/14/aarch64-fix-ice-subreg.patch @@ -0,0 +1,87 @@ +diff --git a/gcc/config/aarch64/aarch64.md b/gcc/config/aarch64/aarch64.md +index d3c381e82ce..6a481059bf0 100644 +--- a/gcc/config/aarch64/aarch64.md ++++ b/gcc/config/aarch64/aarch64.md +@@ -6161,8 +6161,8 @@ + (match_dup 1)) + (match_dup 2))] + { +- operands[2] = lowpart_subreg (mode, operands[2], +- mode); ++ operands[2] = force_lowpart_subreg (mode, operands[2], ++ mode); + } + [(set_attr "type" "bfm,neon_ins_q,neon_ins_q") + (set_attr "arch" "*,simd,simd")] +@@ -7210,7 +7210,7 @@ + + emit_insn (gen_iorv23 ( + lowpart_subreg (V2mode, operands[0], mode), +- lowpart_subreg (V2mode, operands[1], mode), ++ force_lowpart_subreg (V2mode, operands[1], mode), + v_bitmask)); + DONE; + } +@@ -7255,8 +7255,8 @@ + "TARGET_SIMD" + { + rtx tmp = gen_reg_rtx (mode); +- rtx op1 = lowpart_subreg (mode, operands[1], mode); +- rtx op2 = lowpart_subreg (mode, operands[2], mode); ++ rtx op1 = force_lowpart_subreg (mode, operands[1], mode); ++ rtx op2 = force_lowpart_subreg (mode, operands[2], mode); + emit_insn (gen_xorsign3 (mode, tmp, op1, op2)); + emit_move_insn (operands[0], + lowpart_subreg (mode, tmp, mode)); +diff --git a/gcc/explow.cc b/gcc/explow.cc +index f6843398c4b..80f59418bca 100644 +--- a/gcc/explow.cc ++++ b/gcc/explow.cc +@@ -760,6 +760,34 @@ force_subreg (machine_mode outermode, rtx op, + return simplify_gen_subreg (outermode, op, innermode, byte); + } + ++/* Try to return an rvalue expression for the OUTERMODE lowpart of OP, ++ which has mode INNERMODE. Allow OP to be forced into a new register ++ if necessary. ++ ++ Return null on failure. */ ++ ++rtx ++force_lowpart_subreg (machine_mode outermode, rtx op, ++ machine_mode innermode) ++{ ++ auto byte = subreg_lowpart_offset (outermode, innermode); ++ return force_subreg (outermode, op, innermode, byte); ++} ++ ++/* Try to return an rvalue expression for the OUTERMODE highpart of OP, ++ which has mode INNERMODE. Allow OP to be forced into a new register ++ if necessary. ++ ++ Return null on failure. */ ++ ++rtx ++force_highpart_subreg (machine_mode outermode, rtx op, ++ machine_mode innermode) ++{ ++ auto byte = subreg_highpart_offset (outermode, innermode); ++ return force_subreg (outermode, op, innermode, byte); ++} ++ + /* If X is a memory ref, copy its contents to a new temp reg and return + that reg. Otherwise, return X. */ + +diff --git a/gcc/explow.h b/gcc/explow.h +index cbd1fcb7eb3..de89e9e2933 100644 +--- a/gcc/explow.h ++++ b/gcc/explow.h +@@ -43,6 +43,8 @@ extern rtx copy_to_suggested_reg (rtx, rtx, machine_mode); + extern rtx force_reg (machine_mode, rtx); + + extern rtx force_subreg (machine_mode, rtx, machine_mode, poly_uint64); ++extern rtx force_lowpart_subreg (machine_mode, rtx, machine_mode); ++extern rtx force_highpart_subreg (machine_mode, rtx, machine_mode); + + /* Return given rtx, copied into a new temp reg if it was in memory. */ + extern rtx force_not_mem (rtx); diff --git a/pkgs/development/compilers/gcc/patches/default.nix b/pkgs/development/compilers/gcc/patches/default.nix index 7adc06b35779..598c42a48d3e 100644 --- a/pkgs/development/compilers/gcc/patches/default.nix +++ b/pkgs/development/compilers/gcc/patches/default.nix @@ -94,6 +94,11 @@ in ++ optional langD ./libphobos.patch ++ optional (!atLeast14) ./cfi_startproc-reorder-label-09-1.diff ++ optional (atLeast14 && !canApplyIainsDarwinPatches) ./cfi_startproc-reorder-label-14-1.diff +# backports of https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118501 +# and https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118892 +# and https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119133 +# (hopefully all three will be included in the upcoming 14.3.0 release) +++ optional is14 ./14/aarch64-fix-ice-subreg.patch ## 2. Patches relevant to gcc>=12 on specific platforms ####################################