From 1f18c9a29efab50c179a453d076b81d59d77b2d1 Mon Sep 17 00:00:00 2001 From: Oliver Smith Date: Sun, 2 Nov 2025 13:28:40 +0100 Subject: [PATCH] cross/gcc-*: upgrade to 15.2.0-r2 Part-of: --- ...llow-valid-binary-op-when-optimize-c.patch | 130 ++++++++++++++++++ cross/gcc-aarch64/APKBUILD | 4 +- ...llow-valid-binary-op-when-optimize-c.patch | 130 ++++++++++++++++++ cross/gcc-armhf/APKBUILD | 4 +- ...llow-valid-binary-op-when-optimize-c.patch | 130 ++++++++++++++++++ cross/gcc-armv7/APKBUILD | 4 +- ...llow-valid-binary-op-when-optimize-c.patch | 130 ++++++++++++++++++ cross/gcc-loongarch64/APKBUILD | 4 +- ...llow-valid-binary-op-when-optimize-c.patch | 130 ++++++++++++++++++ cross/gcc-ppc64le/APKBUILD | 4 +- ...llow-valid-binary-op-when-optimize-c.patch | 130 ++++++++++++++++++ cross/gcc-riscv64/APKBUILD | 4 +- ...llow-valid-binary-op-when-optimize-c.patch | 130 ++++++++++++++++++ cross/gcc-x86/APKBUILD | 4 +- ...llow-valid-binary-op-when-optimize-c.patch | 130 ++++++++++++++++++ cross/gcc-x86_64/APKBUILD | 4 +- 16 files changed, 1064 insertions(+), 8 deletions(-) create mode 100644 cross/gcc-aarch64/0001-LoongArch-Only-allow-valid-binary-op-when-optimize-c.patch create mode 100644 cross/gcc-armhf/0001-LoongArch-Only-allow-valid-binary-op-when-optimize-c.patch create mode 100644 cross/gcc-armv7/0001-LoongArch-Only-allow-valid-binary-op-when-optimize-c.patch create mode 100644 cross/gcc-loongarch64/0001-LoongArch-Only-allow-valid-binary-op-when-optimize-c.patch create mode 100644 cross/gcc-ppc64le/0001-LoongArch-Only-allow-valid-binary-op-when-optimize-c.patch create mode 100644 cross/gcc-riscv64/0001-LoongArch-Only-allow-valid-binary-op-when-optimize-c.patch create mode 100644 cross/gcc-x86/0001-LoongArch-Only-allow-valid-binary-op-when-optimize-c.patch create mode 100644 cross/gcc-x86_64/0001-LoongArch-Only-allow-valid-binary-op-when-optimize-c.patch diff --git a/cross/gcc-aarch64/0001-LoongArch-Only-allow-valid-binary-op-when-optimize-c.patch b/cross/gcc-aarch64/0001-LoongArch-Only-allow-valid-binary-op-when-optimize-c.patch new file mode 100644 index 000000000..d10f4e51e --- /dev/null +++ b/cross/gcc-aarch64/0001-LoongArch-Only-allow-valid-binary-op-when-optimize-c.patch @@ -0,0 +1,130 @@ +From 824eae920f0f64dd7687c969a2436b129161fdc9 Mon Sep 17 00:00:00 2001 +From: Jinyang He +Date: Wed, 29 Oct 2025 16:07:35 +0800 +Subject: [PATCH] LoongArch: Only allow valid binary op when optimize + conditional move + +It is wrong that optimize from `if (cond) dest op= 1 << shift` to +`dest op= (cond ? 1 : 0) << shift` when `dest op 0 != dest`. +Like `and`, `mul` or `div`. +And in this optimization `mul` and `div` is optimized to shift. + +gcc/ChangeLog: + + * config/loongarch/loongarch.cc + (loongarch_expand_conditional_move): Only allow valid binary + op when optimize conditional move. + +gcc/testsuite/ChangeLog: + + * gcc.target/loongarch/conditional-move-opt-1.c: Remove mul. + * gcc.target/loongarch/conditional-move-opt-2.c: Remove and. + * gcc.target/loongarch/conditional-move-opt-3.c: New test. + +Co-Authored-By: Peng Fan +--- + gcc/config/loongarch/loongarch.cc | 26 ++++++++++++++++--- + .../loongarch/conditional-move-opt-1.c | 4 +-- + .../loongarch/conditional-move-opt-2.c | 2 +- + .../loongarch/conditional-move-opt-3.c | 14 ++++++++++ + 4 files changed, 40 insertions(+), 6 deletions(-) + create mode 100644 gcc/testsuite/gcc.target/loongarch/conditional-move-opt-3.c + +diff --git a/gcc/config/loongarch/loongarch.cc b/gcc/config/loongarch/loongarch.cc +index bdf290654..740c8611a 100644 +--- a/gcc/config/loongarch/loongarch.cc ++++ b/gcc/config/loongarch/loongarch.cc +@@ -5533,12 +5533,32 @@ loongarch_expand_conditional_move (rtx *operands) + } + } + ++ auto is_binary_op_0_keep_orig = [](enum rtx_code code) ++ { ++ switch (code) ++ { ++ case PLUS: ++ case MINUS: ++ case IOR: ++ case XOR: ++ case ROTATE: ++ case ROTATERT: ++ case ASHIFT: ++ case ASHIFTRT: ++ case LSHIFTRT: ++ return true; ++ default: ++ return false; ++ } ++ }; ++ + /* Check if the optimization conditions are met. */ + if (value_if_true_insn + && value_if_false_insn +- /* Make sure that value_if_false and var are the same. */ +- && BINARY_P (value_if_true_insn_src +- = SET_SRC (single_set (value_if_true_insn))) ++ /* Make sure that the orig value OP 0 keep orig. */ ++ && (value_if_true_insn_src ++ = SET_SRC (single_set (value_if_true_insn))) ++ && is_binary_op_0_keep_orig ( GET_CODE (value_if_true_insn_src)) + /* Make sure that both value_if_true and value_if_false + has the same var. */ + && rtx_equal_p (XEXP (value_if_true_insn_src, 0), +diff --git a/gcc/testsuite/gcc.target/loongarch/conditional-move-opt-1.c b/gcc/testsuite/gcc.target/loongarch/conditional-move-opt-1.c +index ed13471aa..47802aa96 100644 +--- a/gcc/testsuite/gcc.target/loongarch/conditional-move-opt-1.c ++++ b/gcc/testsuite/gcc.target/loongarch/conditional-move-opt-1.c +@@ -27,7 +27,7 @@ void + test_lt () + { + if (lm < ln) +- lr *= (1 << 16); ++ lr += (1 << 16); + lr += lm; + } + +@@ -35,7 +35,7 @@ void + test_le () + { + if (lm <= ln) +- lr = lm * ((long)1 << 32); ++ lr = lm + ((long)1 << 32); + else + lr = lm; + lr += lm; +diff --git a/gcc/testsuite/gcc.target/loongarch/conditional-move-opt-2.c b/gcc/testsuite/gcc.target/loongarch/conditional-move-opt-2.c +index ac72d4d93..743fd5e67 100644 +--- a/gcc/testsuite/gcc.target/loongarch/conditional-move-opt-2.c ++++ b/gcc/testsuite/gcc.target/loongarch/conditional-move-opt-2.c +@@ -29,7 +29,7 @@ void + test_lez () + { + if (lm <= 0) +- lr &= (1 << 16); ++ lr |= (1 << 16); + lr += lm; + } + +diff --git a/gcc/testsuite/gcc.target/loongarch/conditional-move-opt-3.c b/gcc/testsuite/gcc.target/loongarch/conditional-move-opt-3.c +new file mode 100644 +index 000000000..95887980c +--- /dev/null ++++ b/gcc/testsuite/gcc.target/loongarch/conditional-move-opt-3.c +@@ -0,0 +1,14 @@ ++/* { dg-do compile } */ ++/* { dg-options "-O2" } */ ++/* { dg-final { scan-assembler "maskeqz" } } */ ++/* { dg-final { scan-assembler "masknez" } } */ ++ ++extern long lm, ln, lr; ++ ++void ++test_and () ++{ ++ if (lm < 0) ++ lr &= (1 << 16); ++ lr += lm; ++} +-- +2.51.1 + diff --git a/cross/gcc-aarch64/APKBUILD b/cross/gcc-aarch64/APKBUILD index 367fe076d..d560b2954 100644 --- a/cross/gcc-aarch64/APKBUILD +++ b/cross/gcc-aarch64/APKBUILD @@ -34,7 +34,7 @@ _pkgsnap="${pkgver##*_git}" [ "$CHOST" != "$CTARGET" ] && _target="-$CTARGET_ARCH" || _target="" pkgname=gcc-aarch64 -pkgrel=1 +pkgrel=2 pkgdesc="Stage2 cross-compiler for aarch64" url="https://gcc.gnu.org" arch="x86_64" @@ -281,6 +281,7 @@ source="https://gcc.gnu.org/pub/gcc/releases/gcc-$_pkgbase/gcc-$_pkgbase.tar.xz 0041-ada-libgnat-recognize-linux-musleabi-and-linux-muslg.patch 0001-tree-object-size.cc-Fix-assert-constant-offset-in-ch.patch + 0001-LoongArch-Only-allow-valid-binary-op-when-optimize-c.patch " # secfixes: @@ -796,4 +797,5 @@ eecc77e2a9cf956fd752693ad7f8ff8253a7bb557e00564bb488bbc1deac895e63104cc1182a0bdd d166475e340c91bbb24cf257240aab37129b04f2609e5ce323b530ab83853a4c34c525e0072c15732717f1681db07e6b3b0a4d268720c31f460435ccf4c99b7f 0040-ada-libgnat-use-stub-symbolic-module-name-functions.patch c717764ef52c0226a23cbf434654cdefa6cbf38ec625648575d9143c5513b16d8914c25015db743033b8a46ac5b2c33ab75e1b67076128d67bb1319e5a83dd85 0041-ada-libgnat-recognize-linux-musleabi-and-linux-muslg.patch c3b64b05332bd4dd7fad3fff3cacd4f9de0512943f1548c6f1205fab1a74c83622024f30471805f57d625198cc32f647b32172914528fd5605d0bf61cb0c3ff1 0001-tree-object-size.cc-Fix-assert-constant-offset-in-ch.patch +e91873055550eba051d9297bec5c6acd27abb9ee6ce8911cdd04b5faf37d77b6b2a7607ec588d2863f13f14b48af9398cb4ac42443d8567bfa5037dc6bd50404 0001-LoongArch-Only-allow-valid-binary-op-when-optimize-c.patch " diff --git a/cross/gcc-armhf/0001-LoongArch-Only-allow-valid-binary-op-when-optimize-c.patch b/cross/gcc-armhf/0001-LoongArch-Only-allow-valid-binary-op-when-optimize-c.patch new file mode 100644 index 000000000..d10f4e51e --- /dev/null +++ b/cross/gcc-armhf/0001-LoongArch-Only-allow-valid-binary-op-when-optimize-c.patch @@ -0,0 +1,130 @@ +From 824eae920f0f64dd7687c969a2436b129161fdc9 Mon Sep 17 00:00:00 2001 +From: Jinyang He +Date: Wed, 29 Oct 2025 16:07:35 +0800 +Subject: [PATCH] LoongArch: Only allow valid binary op when optimize + conditional move + +It is wrong that optimize from `if (cond) dest op= 1 << shift` to +`dest op= (cond ? 1 : 0) << shift` when `dest op 0 != dest`. +Like `and`, `mul` or `div`. +And in this optimization `mul` and `div` is optimized to shift. + +gcc/ChangeLog: + + * config/loongarch/loongarch.cc + (loongarch_expand_conditional_move): Only allow valid binary + op when optimize conditional move. + +gcc/testsuite/ChangeLog: + + * gcc.target/loongarch/conditional-move-opt-1.c: Remove mul. + * gcc.target/loongarch/conditional-move-opt-2.c: Remove and. + * gcc.target/loongarch/conditional-move-opt-3.c: New test. + +Co-Authored-By: Peng Fan +--- + gcc/config/loongarch/loongarch.cc | 26 ++++++++++++++++--- + .../loongarch/conditional-move-opt-1.c | 4 +-- + .../loongarch/conditional-move-opt-2.c | 2 +- + .../loongarch/conditional-move-opt-3.c | 14 ++++++++++ + 4 files changed, 40 insertions(+), 6 deletions(-) + create mode 100644 gcc/testsuite/gcc.target/loongarch/conditional-move-opt-3.c + +diff --git a/gcc/config/loongarch/loongarch.cc b/gcc/config/loongarch/loongarch.cc +index bdf290654..740c8611a 100644 +--- a/gcc/config/loongarch/loongarch.cc ++++ b/gcc/config/loongarch/loongarch.cc +@@ -5533,12 +5533,32 @@ loongarch_expand_conditional_move (rtx *operands) + } + } + ++ auto is_binary_op_0_keep_orig = [](enum rtx_code code) ++ { ++ switch (code) ++ { ++ case PLUS: ++ case MINUS: ++ case IOR: ++ case XOR: ++ case ROTATE: ++ case ROTATERT: ++ case ASHIFT: ++ case ASHIFTRT: ++ case LSHIFTRT: ++ return true; ++ default: ++ return false; ++ } ++ }; ++ + /* Check if the optimization conditions are met. */ + if (value_if_true_insn + && value_if_false_insn +- /* Make sure that value_if_false and var are the same. */ +- && BINARY_P (value_if_true_insn_src +- = SET_SRC (single_set (value_if_true_insn))) ++ /* Make sure that the orig value OP 0 keep orig. */ ++ && (value_if_true_insn_src ++ = SET_SRC (single_set (value_if_true_insn))) ++ && is_binary_op_0_keep_orig ( GET_CODE (value_if_true_insn_src)) + /* Make sure that both value_if_true and value_if_false + has the same var. */ + && rtx_equal_p (XEXP (value_if_true_insn_src, 0), +diff --git a/gcc/testsuite/gcc.target/loongarch/conditional-move-opt-1.c b/gcc/testsuite/gcc.target/loongarch/conditional-move-opt-1.c +index ed13471aa..47802aa96 100644 +--- a/gcc/testsuite/gcc.target/loongarch/conditional-move-opt-1.c ++++ b/gcc/testsuite/gcc.target/loongarch/conditional-move-opt-1.c +@@ -27,7 +27,7 @@ void + test_lt () + { + if (lm < ln) +- lr *= (1 << 16); ++ lr += (1 << 16); + lr += lm; + } + +@@ -35,7 +35,7 @@ void + test_le () + { + if (lm <= ln) +- lr = lm * ((long)1 << 32); ++ lr = lm + ((long)1 << 32); + else + lr = lm; + lr += lm; +diff --git a/gcc/testsuite/gcc.target/loongarch/conditional-move-opt-2.c b/gcc/testsuite/gcc.target/loongarch/conditional-move-opt-2.c +index ac72d4d93..743fd5e67 100644 +--- a/gcc/testsuite/gcc.target/loongarch/conditional-move-opt-2.c ++++ b/gcc/testsuite/gcc.target/loongarch/conditional-move-opt-2.c +@@ -29,7 +29,7 @@ void + test_lez () + { + if (lm <= 0) +- lr &= (1 << 16); ++ lr |= (1 << 16); + lr += lm; + } + +diff --git a/gcc/testsuite/gcc.target/loongarch/conditional-move-opt-3.c b/gcc/testsuite/gcc.target/loongarch/conditional-move-opt-3.c +new file mode 100644 +index 000000000..95887980c +--- /dev/null ++++ b/gcc/testsuite/gcc.target/loongarch/conditional-move-opt-3.c +@@ -0,0 +1,14 @@ ++/* { dg-do compile } */ ++/* { dg-options "-O2" } */ ++/* { dg-final { scan-assembler "maskeqz" } } */ ++/* { dg-final { scan-assembler "masknez" } } */ ++ ++extern long lm, ln, lr; ++ ++void ++test_and () ++{ ++ if (lm < 0) ++ lr &= (1 << 16); ++ lr += lm; ++} +-- +2.51.1 + diff --git a/cross/gcc-armhf/APKBUILD b/cross/gcc-armhf/APKBUILD index 158ebc0a6..f41b8fe40 100644 --- a/cross/gcc-armhf/APKBUILD +++ b/cross/gcc-armhf/APKBUILD @@ -34,7 +34,7 @@ _pkgsnap="${pkgver##*_git}" [ "$CHOST" != "$CTARGET" ] && _target="-$CTARGET_ARCH" || _target="" pkgname=gcc-armhf -pkgrel=1 +pkgrel=2 pkgdesc="Stage2 cross-compiler for armhf" url="https://gcc.gnu.org" arch="x86_64" @@ -281,6 +281,7 @@ source="https://gcc.gnu.org/pub/gcc/releases/gcc-$_pkgbase/gcc-$_pkgbase.tar.xz 0041-ada-libgnat-recognize-linux-musleabi-and-linux-muslg.patch 0001-tree-object-size.cc-Fix-assert-constant-offset-in-ch.patch + 0001-LoongArch-Only-allow-valid-binary-op-when-optimize-c.patch " # secfixes: @@ -796,4 +797,5 @@ eecc77e2a9cf956fd752693ad7f8ff8253a7bb557e00564bb488bbc1deac895e63104cc1182a0bdd d166475e340c91bbb24cf257240aab37129b04f2609e5ce323b530ab83853a4c34c525e0072c15732717f1681db07e6b3b0a4d268720c31f460435ccf4c99b7f 0040-ada-libgnat-use-stub-symbolic-module-name-functions.patch c717764ef52c0226a23cbf434654cdefa6cbf38ec625648575d9143c5513b16d8914c25015db743033b8a46ac5b2c33ab75e1b67076128d67bb1319e5a83dd85 0041-ada-libgnat-recognize-linux-musleabi-and-linux-muslg.patch c3b64b05332bd4dd7fad3fff3cacd4f9de0512943f1548c6f1205fab1a74c83622024f30471805f57d625198cc32f647b32172914528fd5605d0bf61cb0c3ff1 0001-tree-object-size.cc-Fix-assert-constant-offset-in-ch.patch +e91873055550eba051d9297bec5c6acd27abb9ee6ce8911cdd04b5faf37d77b6b2a7607ec588d2863f13f14b48af9398cb4ac42443d8567bfa5037dc6bd50404 0001-LoongArch-Only-allow-valid-binary-op-when-optimize-c.patch " diff --git a/cross/gcc-armv7/0001-LoongArch-Only-allow-valid-binary-op-when-optimize-c.patch b/cross/gcc-armv7/0001-LoongArch-Only-allow-valid-binary-op-when-optimize-c.patch new file mode 100644 index 000000000..d10f4e51e --- /dev/null +++ b/cross/gcc-armv7/0001-LoongArch-Only-allow-valid-binary-op-when-optimize-c.patch @@ -0,0 +1,130 @@ +From 824eae920f0f64dd7687c969a2436b129161fdc9 Mon Sep 17 00:00:00 2001 +From: Jinyang He +Date: Wed, 29 Oct 2025 16:07:35 +0800 +Subject: [PATCH] LoongArch: Only allow valid binary op when optimize + conditional move + +It is wrong that optimize from `if (cond) dest op= 1 << shift` to +`dest op= (cond ? 1 : 0) << shift` when `dest op 0 != dest`. +Like `and`, `mul` or `div`. +And in this optimization `mul` and `div` is optimized to shift. + +gcc/ChangeLog: + + * config/loongarch/loongarch.cc + (loongarch_expand_conditional_move): Only allow valid binary + op when optimize conditional move. + +gcc/testsuite/ChangeLog: + + * gcc.target/loongarch/conditional-move-opt-1.c: Remove mul. + * gcc.target/loongarch/conditional-move-opt-2.c: Remove and. + * gcc.target/loongarch/conditional-move-opt-3.c: New test. + +Co-Authored-By: Peng Fan +--- + gcc/config/loongarch/loongarch.cc | 26 ++++++++++++++++--- + .../loongarch/conditional-move-opt-1.c | 4 +-- + .../loongarch/conditional-move-opt-2.c | 2 +- + .../loongarch/conditional-move-opt-3.c | 14 ++++++++++ + 4 files changed, 40 insertions(+), 6 deletions(-) + create mode 100644 gcc/testsuite/gcc.target/loongarch/conditional-move-opt-3.c + +diff --git a/gcc/config/loongarch/loongarch.cc b/gcc/config/loongarch/loongarch.cc +index bdf290654..740c8611a 100644 +--- a/gcc/config/loongarch/loongarch.cc ++++ b/gcc/config/loongarch/loongarch.cc +@@ -5533,12 +5533,32 @@ loongarch_expand_conditional_move (rtx *operands) + } + } + ++ auto is_binary_op_0_keep_orig = [](enum rtx_code code) ++ { ++ switch (code) ++ { ++ case PLUS: ++ case MINUS: ++ case IOR: ++ case XOR: ++ case ROTATE: ++ case ROTATERT: ++ case ASHIFT: ++ case ASHIFTRT: ++ case LSHIFTRT: ++ return true; ++ default: ++ return false; ++ } ++ }; ++ + /* Check if the optimization conditions are met. */ + if (value_if_true_insn + && value_if_false_insn +- /* Make sure that value_if_false and var are the same. */ +- && BINARY_P (value_if_true_insn_src +- = SET_SRC (single_set (value_if_true_insn))) ++ /* Make sure that the orig value OP 0 keep orig. */ ++ && (value_if_true_insn_src ++ = SET_SRC (single_set (value_if_true_insn))) ++ && is_binary_op_0_keep_orig ( GET_CODE (value_if_true_insn_src)) + /* Make sure that both value_if_true and value_if_false + has the same var. */ + && rtx_equal_p (XEXP (value_if_true_insn_src, 0), +diff --git a/gcc/testsuite/gcc.target/loongarch/conditional-move-opt-1.c b/gcc/testsuite/gcc.target/loongarch/conditional-move-opt-1.c +index ed13471aa..47802aa96 100644 +--- a/gcc/testsuite/gcc.target/loongarch/conditional-move-opt-1.c ++++ b/gcc/testsuite/gcc.target/loongarch/conditional-move-opt-1.c +@@ -27,7 +27,7 @@ void + test_lt () + { + if (lm < ln) +- lr *= (1 << 16); ++ lr += (1 << 16); + lr += lm; + } + +@@ -35,7 +35,7 @@ void + test_le () + { + if (lm <= ln) +- lr = lm * ((long)1 << 32); ++ lr = lm + ((long)1 << 32); + else + lr = lm; + lr += lm; +diff --git a/gcc/testsuite/gcc.target/loongarch/conditional-move-opt-2.c b/gcc/testsuite/gcc.target/loongarch/conditional-move-opt-2.c +index ac72d4d93..743fd5e67 100644 +--- a/gcc/testsuite/gcc.target/loongarch/conditional-move-opt-2.c ++++ b/gcc/testsuite/gcc.target/loongarch/conditional-move-opt-2.c +@@ -29,7 +29,7 @@ void + test_lez () + { + if (lm <= 0) +- lr &= (1 << 16); ++ lr |= (1 << 16); + lr += lm; + } + +diff --git a/gcc/testsuite/gcc.target/loongarch/conditional-move-opt-3.c b/gcc/testsuite/gcc.target/loongarch/conditional-move-opt-3.c +new file mode 100644 +index 000000000..95887980c +--- /dev/null ++++ b/gcc/testsuite/gcc.target/loongarch/conditional-move-opt-3.c +@@ -0,0 +1,14 @@ ++/* { dg-do compile } */ ++/* { dg-options "-O2" } */ ++/* { dg-final { scan-assembler "maskeqz" } } */ ++/* { dg-final { scan-assembler "masknez" } } */ ++ ++extern long lm, ln, lr; ++ ++void ++test_and () ++{ ++ if (lm < 0) ++ lr &= (1 << 16); ++ lr += lm; ++} +-- +2.51.1 + diff --git a/cross/gcc-armv7/APKBUILD b/cross/gcc-armv7/APKBUILD index 4b45062ec..e45be9561 100644 --- a/cross/gcc-armv7/APKBUILD +++ b/cross/gcc-armv7/APKBUILD @@ -34,7 +34,7 @@ _pkgsnap="${pkgver##*_git}" [ "$CHOST" != "$CTARGET" ] && _target="-$CTARGET_ARCH" || _target="" pkgname=gcc-armv7 -pkgrel=1 +pkgrel=2 pkgdesc="Stage2 cross-compiler for armv7" url="https://gcc.gnu.org" arch="x86_64" @@ -281,6 +281,7 @@ source="https://gcc.gnu.org/pub/gcc/releases/gcc-$_pkgbase/gcc-$_pkgbase.tar.xz 0041-ada-libgnat-recognize-linux-musleabi-and-linux-muslg.patch 0001-tree-object-size.cc-Fix-assert-constant-offset-in-ch.patch + 0001-LoongArch-Only-allow-valid-binary-op-when-optimize-c.patch " # secfixes: @@ -796,4 +797,5 @@ eecc77e2a9cf956fd752693ad7f8ff8253a7bb557e00564bb488bbc1deac895e63104cc1182a0bdd d166475e340c91bbb24cf257240aab37129b04f2609e5ce323b530ab83853a4c34c525e0072c15732717f1681db07e6b3b0a4d268720c31f460435ccf4c99b7f 0040-ada-libgnat-use-stub-symbolic-module-name-functions.patch c717764ef52c0226a23cbf434654cdefa6cbf38ec625648575d9143c5513b16d8914c25015db743033b8a46ac5b2c33ab75e1b67076128d67bb1319e5a83dd85 0041-ada-libgnat-recognize-linux-musleabi-and-linux-muslg.patch c3b64b05332bd4dd7fad3fff3cacd4f9de0512943f1548c6f1205fab1a74c83622024f30471805f57d625198cc32f647b32172914528fd5605d0bf61cb0c3ff1 0001-tree-object-size.cc-Fix-assert-constant-offset-in-ch.patch +e91873055550eba051d9297bec5c6acd27abb9ee6ce8911cdd04b5faf37d77b6b2a7607ec588d2863f13f14b48af9398cb4ac42443d8567bfa5037dc6bd50404 0001-LoongArch-Only-allow-valid-binary-op-when-optimize-c.patch " diff --git a/cross/gcc-loongarch64/0001-LoongArch-Only-allow-valid-binary-op-when-optimize-c.patch b/cross/gcc-loongarch64/0001-LoongArch-Only-allow-valid-binary-op-when-optimize-c.patch new file mode 100644 index 000000000..d10f4e51e --- /dev/null +++ b/cross/gcc-loongarch64/0001-LoongArch-Only-allow-valid-binary-op-when-optimize-c.patch @@ -0,0 +1,130 @@ +From 824eae920f0f64dd7687c969a2436b129161fdc9 Mon Sep 17 00:00:00 2001 +From: Jinyang He +Date: Wed, 29 Oct 2025 16:07:35 +0800 +Subject: [PATCH] LoongArch: Only allow valid binary op when optimize + conditional move + +It is wrong that optimize from `if (cond) dest op= 1 << shift` to +`dest op= (cond ? 1 : 0) << shift` when `dest op 0 != dest`. +Like `and`, `mul` or `div`. +And in this optimization `mul` and `div` is optimized to shift. + +gcc/ChangeLog: + + * config/loongarch/loongarch.cc + (loongarch_expand_conditional_move): Only allow valid binary + op when optimize conditional move. + +gcc/testsuite/ChangeLog: + + * gcc.target/loongarch/conditional-move-opt-1.c: Remove mul. + * gcc.target/loongarch/conditional-move-opt-2.c: Remove and. + * gcc.target/loongarch/conditional-move-opt-3.c: New test. + +Co-Authored-By: Peng Fan +--- + gcc/config/loongarch/loongarch.cc | 26 ++++++++++++++++--- + .../loongarch/conditional-move-opt-1.c | 4 +-- + .../loongarch/conditional-move-opt-2.c | 2 +- + .../loongarch/conditional-move-opt-3.c | 14 ++++++++++ + 4 files changed, 40 insertions(+), 6 deletions(-) + create mode 100644 gcc/testsuite/gcc.target/loongarch/conditional-move-opt-3.c + +diff --git a/gcc/config/loongarch/loongarch.cc b/gcc/config/loongarch/loongarch.cc +index bdf290654..740c8611a 100644 +--- a/gcc/config/loongarch/loongarch.cc ++++ b/gcc/config/loongarch/loongarch.cc +@@ -5533,12 +5533,32 @@ loongarch_expand_conditional_move (rtx *operands) + } + } + ++ auto is_binary_op_0_keep_orig = [](enum rtx_code code) ++ { ++ switch (code) ++ { ++ case PLUS: ++ case MINUS: ++ case IOR: ++ case XOR: ++ case ROTATE: ++ case ROTATERT: ++ case ASHIFT: ++ case ASHIFTRT: ++ case LSHIFTRT: ++ return true; ++ default: ++ return false; ++ } ++ }; ++ + /* Check if the optimization conditions are met. */ + if (value_if_true_insn + && value_if_false_insn +- /* Make sure that value_if_false and var are the same. */ +- && BINARY_P (value_if_true_insn_src +- = SET_SRC (single_set (value_if_true_insn))) ++ /* Make sure that the orig value OP 0 keep orig. */ ++ && (value_if_true_insn_src ++ = SET_SRC (single_set (value_if_true_insn))) ++ && is_binary_op_0_keep_orig ( GET_CODE (value_if_true_insn_src)) + /* Make sure that both value_if_true and value_if_false + has the same var. */ + && rtx_equal_p (XEXP (value_if_true_insn_src, 0), +diff --git a/gcc/testsuite/gcc.target/loongarch/conditional-move-opt-1.c b/gcc/testsuite/gcc.target/loongarch/conditional-move-opt-1.c +index ed13471aa..47802aa96 100644 +--- a/gcc/testsuite/gcc.target/loongarch/conditional-move-opt-1.c ++++ b/gcc/testsuite/gcc.target/loongarch/conditional-move-opt-1.c +@@ -27,7 +27,7 @@ void + test_lt () + { + if (lm < ln) +- lr *= (1 << 16); ++ lr += (1 << 16); + lr += lm; + } + +@@ -35,7 +35,7 @@ void + test_le () + { + if (lm <= ln) +- lr = lm * ((long)1 << 32); ++ lr = lm + ((long)1 << 32); + else + lr = lm; + lr += lm; +diff --git a/gcc/testsuite/gcc.target/loongarch/conditional-move-opt-2.c b/gcc/testsuite/gcc.target/loongarch/conditional-move-opt-2.c +index ac72d4d93..743fd5e67 100644 +--- a/gcc/testsuite/gcc.target/loongarch/conditional-move-opt-2.c ++++ b/gcc/testsuite/gcc.target/loongarch/conditional-move-opt-2.c +@@ -29,7 +29,7 @@ void + test_lez () + { + if (lm <= 0) +- lr &= (1 << 16); ++ lr |= (1 << 16); + lr += lm; + } + +diff --git a/gcc/testsuite/gcc.target/loongarch/conditional-move-opt-3.c b/gcc/testsuite/gcc.target/loongarch/conditional-move-opt-3.c +new file mode 100644 +index 000000000..95887980c +--- /dev/null ++++ b/gcc/testsuite/gcc.target/loongarch/conditional-move-opt-3.c +@@ -0,0 +1,14 @@ ++/* { dg-do compile } */ ++/* { dg-options "-O2" } */ ++/* { dg-final { scan-assembler "maskeqz" } } */ ++/* { dg-final { scan-assembler "masknez" } } */ ++ ++extern long lm, ln, lr; ++ ++void ++test_and () ++{ ++ if (lm < 0) ++ lr &= (1 << 16); ++ lr += lm; ++} +-- +2.51.1 + diff --git a/cross/gcc-loongarch64/APKBUILD b/cross/gcc-loongarch64/APKBUILD index b742ff513..7f4dbed15 100644 --- a/cross/gcc-loongarch64/APKBUILD +++ b/cross/gcc-loongarch64/APKBUILD @@ -34,7 +34,7 @@ _pkgsnap="${pkgver##*_git}" [ "$CHOST" != "$CTARGET" ] && _target="-$CTARGET_ARCH" || _target="" pkgname=gcc-loongarch64 -pkgrel=1 +pkgrel=2 pkgdesc="Stage2 cross-compiler for loongarch64" url="https://gcc.gnu.org" arch="x86_64" @@ -281,6 +281,7 @@ source="https://gcc.gnu.org/pub/gcc/releases/gcc-$_pkgbase/gcc-$_pkgbase.tar.xz 0041-ada-libgnat-recognize-linux-musleabi-and-linux-muslg.patch 0001-tree-object-size.cc-Fix-assert-constant-offset-in-ch.patch + 0001-LoongArch-Only-allow-valid-binary-op-when-optimize-c.patch " # secfixes: @@ -796,4 +797,5 @@ eecc77e2a9cf956fd752693ad7f8ff8253a7bb557e00564bb488bbc1deac895e63104cc1182a0bdd d166475e340c91bbb24cf257240aab37129b04f2609e5ce323b530ab83853a4c34c525e0072c15732717f1681db07e6b3b0a4d268720c31f460435ccf4c99b7f 0040-ada-libgnat-use-stub-symbolic-module-name-functions.patch c717764ef52c0226a23cbf434654cdefa6cbf38ec625648575d9143c5513b16d8914c25015db743033b8a46ac5b2c33ab75e1b67076128d67bb1319e5a83dd85 0041-ada-libgnat-recognize-linux-musleabi-and-linux-muslg.patch c3b64b05332bd4dd7fad3fff3cacd4f9de0512943f1548c6f1205fab1a74c83622024f30471805f57d625198cc32f647b32172914528fd5605d0bf61cb0c3ff1 0001-tree-object-size.cc-Fix-assert-constant-offset-in-ch.patch +e91873055550eba051d9297bec5c6acd27abb9ee6ce8911cdd04b5faf37d77b6b2a7607ec588d2863f13f14b48af9398cb4ac42443d8567bfa5037dc6bd50404 0001-LoongArch-Only-allow-valid-binary-op-when-optimize-c.patch " diff --git a/cross/gcc-ppc64le/0001-LoongArch-Only-allow-valid-binary-op-when-optimize-c.patch b/cross/gcc-ppc64le/0001-LoongArch-Only-allow-valid-binary-op-when-optimize-c.patch new file mode 100644 index 000000000..d10f4e51e --- /dev/null +++ b/cross/gcc-ppc64le/0001-LoongArch-Only-allow-valid-binary-op-when-optimize-c.patch @@ -0,0 +1,130 @@ +From 824eae920f0f64dd7687c969a2436b129161fdc9 Mon Sep 17 00:00:00 2001 +From: Jinyang He +Date: Wed, 29 Oct 2025 16:07:35 +0800 +Subject: [PATCH] LoongArch: Only allow valid binary op when optimize + conditional move + +It is wrong that optimize from `if (cond) dest op= 1 << shift` to +`dest op= (cond ? 1 : 0) << shift` when `dest op 0 != dest`. +Like `and`, `mul` or `div`. +And in this optimization `mul` and `div` is optimized to shift. + +gcc/ChangeLog: + + * config/loongarch/loongarch.cc + (loongarch_expand_conditional_move): Only allow valid binary + op when optimize conditional move. + +gcc/testsuite/ChangeLog: + + * gcc.target/loongarch/conditional-move-opt-1.c: Remove mul. + * gcc.target/loongarch/conditional-move-opt-2.c: Remove and. + * gcc.target/loongarch/conditional-move-opt-3.c: New test. + +Co-Authored-By: Peng Fan +--- + gcc/config/loongarch/loongarch.cc | 26 ++++++++++++++++--- + .../loongarch/conditional-move-opt-1.c | 4 +-- + .../loongarch/conditional-move-opt-2.c | 2 +- + .../loongarch/conditional-move-opt-3.c | 14 ++++++++++ + 4 files changed, 40 insertions(+), 6 deletions(-) + create mode 100644 gcc/testsuite/gcc.target/loongarch/conditional-move-opt-3.c + +diff --git a/gcc/config/loongarch/loongarch.cc b/gcc/config/loongarch/loongarch.cc +index bdf290654..740c8611a 100644 +--- a/gcc/config/loongarch/loongarch.cc ++++ b/gcc/config/loongarch/loongarch.cc +@@ -5533,12 +5533,32 @@ loongarch_expand_conditional_move (rtx *operands) + } + } + ++ auto is_binary_op_0_keep_orig = [](enum rtx_code code) ++ { ++ switch (code) ++ { ++ case PLUS: ++ case MINUS: ++ case IOR: ++ case XOR: ++ case ROTATE: ++ case ROTATERT: ++ case ASHIFT: ++ case ASHIFTRT: ++ case LSHIFTRT: ++ return true; ++ default: ++ return false; ++ } ++ }; ++ + /* Check if the optimization conditions are met. */ + if (value_if_true_insn + && value_if_false_insn +- /* Make sure that value_if_false and var are the same. */ +- && BINARY_P (value_if_true_insn_src +- = SET_SRC (single_set (value_if_true_insn))) ++ /* Make sure that the orig value OP 0 keep orig. */ ++ && (value_if_true_insn_src ++ = SET_SRC (single_set (value_if_true_insn))) ++ && is_binary_op_0_keep_orig ( GET_CODE (value_if_true_insn_src)) + /* Make sure that both value_if_true and value_if_false + has the same var. */ + && rtx_equal_p (XEXP (value_if_true_insn_src, 0), +diff --git a/gcc/testsuite/gcc.target/loongarch/conditional-move-opt-1.c b/gcc/testsuite/gcc.target/loongarch/conditional-move-opt-1.c +index ed13471aa..47802aa96 100644 +--- a/gcc/testsuite/gcc.target/loongarch/conditional-move-opt-1.c ++++ b/gcc/testsuite/gcc.target/loongarch/conditional-move-opt-1.c +@@ -27,7 +27,7 @@ void + test_lt () + { + if (lm < ln) +- lr *= (1 << 16); ++ lr += (1 << 16); + lr += lm; + } + +@@ -35,7 +35,7 @@ void + test_le () + { + if (lm <= ln) +- lr = lm * ((long)1 << 32); ++ lr = lm + ((long)1 << 32); + else + lr = lm; + lr += lm; +diff --git a/gcc/testsuite/gcc.target/loongarch/conditional-move-opt-2.c b/gcc/testsuite/gcc.target/loongarch/conditional-move-opt-2.c +index ac72d4d93..743fd5e67 100644 +--- a/gcc/testsuite/gcc.target/loongarch/conditional-move-opt-2.c ++++ b/gcc/testsuite/gcc.target/loongarch/conditional-move-opt-2.c +@@ -29,7 +29,7 @@ void + test_lez () + { + if (lm <= 0) +- lr &= (1 << 16); ++ lr |= (1 << 16); + lr += lm; + } + +diff --git a/gcc/testsuite/gcc.target/loongarch/conditional-move-opt-3.c b/gcc/testsuite/gcc.target/loongarch/conditional-move-opt-3.c +new file mode 100644 +index 000000000..95887980c +--- /dev/null ++++ b/gcc/testsuite/gcc.target/loongarch/conditional-move-opt-3.c +@@ -0,0 +1,14 @@ ++/* { dg-do compile } */ ++/* { dg-options "-O2" } */ ++/* { dg-final { scan-assembler "maskeqz" } } */ ++/* { dg-final { scan-assembler "masknez" } } */ ++ ++extern long lm, ln, lr; ++ ++void ++test_and () ++{ ++ if (lm < 0) ++ lr &= (1 << 16); ++ lr += lm; ++} +-- +2.51.1 + diff --git a/cross/gcc-ppc64le/APKBUILD b/cross/gcc-ppc64le/APKBUILD index 4dc68c6e4..faf33abff 100644 --- a/cross/gcc-ppc64le/APKBUILD +++ b/cross/gcc-ppc64le/APKBUILD @@ -34,7 +34,7 @@ _pkgsnap="${pkgver##*_git}" [ "$CHOST" != "$CTARGET" ] && _target="-$CTARGET_ARCH" || _target="" pkgname=gcc-ppc64le -pkgrel=1 +pkgrel=2 pkgdesc="Stage2 cross-compiler for ppc64le" url="https://gcc.gnu.org" arch="x86_64" @@ -281,6 +281,7 @@ source="https://gcc.gnu.org/pub/gcc/releases/gcc-$_pkgbase/gcc-$_pkgbase.tar.xz 0041-ada-libgnat-recognize-linux-musleabi-and-linux-muslg.patch 0001-tree-object-size.cc-Fix-assert-constant-offset-in-ch.patch + 0001-LoongArch-Only-allow-valid-binary-op-when-optimize-c.patch " # secfixes: @@ -796,4 +797,5 @@ eecc77e2a9cf956fd752693ad7f8ff8253a7bb557e00564bb488bbc1deac895e63104cc1182a0bdd d166475e340c91bbb24cf257240aab37129b04f2609e5ce323b530ab83853a4c34c525e0072c15732717f1681db07e6b3b0a4d268720c31f460435ccf4c99b7f 0040-ada-libgnat-use-stub-symbolic-module-name-functions.patch c717764ef52c0226a23cbf434654cdefa6cbf38ec625648575d9143c5513b16d8914c25015db743033b8a46ac5b2c33ab75e1b67076128d67bb1319e5a83dd85 0041-ada-libgnat-recognize-linux-musleabi-and-linux-muslg.patch c3b64b05332bd4dd7fad3fff3cacd4f9de0512943f1548c6f1205fab1a74c83622024f30471805f57d625198cc32f647b32172914528fd5605d0bf61cb0c3ff1 0001-tree-object-size.cc-Fix-assert-constant-offset-in-ch.patch +e91873055550eba051d9297bec5c6acd27abb9ee6ce8911cdd04b5faf37d77b6b2a7607ec588d2863f13f14b48af9398cb4ac42443d8567bfa5037dc6bd50404 0001-LoongArch-Only-allow-valid-binary-op-when-optimize-c.patch " diff --git a/cross/gcc-riscv64/0001-LoongArch-Only-allow-valid-binary-op-when-optimize-c.patch b/cross/gcc-riscv64/0001-LoongArch-Only-allow-valid-binary-op-when-optimize-c.patch new file mode 100644 index 000000000..d10f4e51e --- /dev/null +++ b/cross/gcc-riscv64/0001-LoongArch-Only-allow-valid-binary-op-when-optimize-c.patch @@ -0,0 +1,130 @@ +From 824eae920f0f64dd7687c969a2436b129161fdc9 Mon Sep 17 00:00:00 2001 +From: Jinyang He +Date: Wed, 29 Oct 2025 16:07:35 +0800 +Subject: [PATCH] LoongArch: Only allow valid binary op when optimize + conditional move + +It is wrong that optimize from `if (cond) dest op= 1 << shift` to +`dest op= (cond ? 1 : 0) << shift` when `dest op 0 != dest`. +Like `and`, `mul` or `div`. +And in this optimization `mul` and `div` is optimized to shift. + +gcc/ChangeLog: + + * config/loongarch/loongarch.cc + (loongarch_expand_conditional_move): Only allow valid binary + op when optimize conditional move. + +gcc/testsuite/ChangeLog: + + * gcc.target/loongarch/conditional-move-opt-1.c: Remove mul. + * gcc.target/loongarch/conditional-move-opt-2.c: Remove and. + * gcc.target/loongarch/conditional-move-opt-3.c: New test. + +Co-Authored-By: Peng Fan +--- + gcc/config/loongarch/loongarch.cc | 26 ++++++++++++++++--- + .../loongarch/conditional-move-opt-1.c | 4 +-- + .../loongarch/conditional-move-opt-2.c | 2 +- + .../loongarch/conditional-move-opt-3.c | 14 ++++++++++ + 4 files changed, 40 insertions(+), 6 deletions(-) + create mode 100644 gcc/testsuite/gcc.target/loongarch/conditional-move-opt-3.c + +diff --git a/gcc/config/loongarch/loongarch.cc b/gcc/config/loongarch/loongarch.cc +index bdf290654..740c8611a 100644 +--- a/gcc/config/loongarch/loongarch.cc ++++ b/gcc/config/loongarch/loongarch.cc +@@ -5533,12 +5533,32 @@ loongarch_expand_conditional_move (rtx *operands) + } + } + ++ auto is_binary_op_0_keep_orig = [](enum rtx_code code) ++ { ++ switch (code) ++ { ++ case PLUS: ++ case MINUS: ++ case IOR: ++ case XOR: ++ case ROTATE: ++ case ROTATERT: ++ case ASHIFT: ++ case ASHIFTRT: ++ case LSHIFTRT: ++ return true; ++ default: ++ return false; ++ } ++ }; ++ + /* Check if the optimization conditions are met. */ + if (value_if_true_insn + && value_if_false_insn +- /* Make sure that value_if_false and var are the same. */ +- && BINARY_P (value_if_true_insn_src +- = SET_SRC (single_set (value_if_true_insn))) ++ /* Make sure that the orig value OP 0 keep orig. */ ++ && (value_if_true_insn_src ++ = SET_SRC (single_set (value_if_true_insn))) ++ && is_binary_op_0_keep_orig ( GET_CODE (value_if_true_insn_src)) + /* Make sure that both value_if_true and value_if_false + has the same var. */ + && rtx_equal_p (XEXP (value_if_true_insn_src, 0), +diff --git a/gcc/testsuite/gcc.target/loongarch/conditional-move-opt-1.c b/gcc/testsuite/gcc.target/loongarch/conditional-move-opt-1.c +index ed13471aa..47802aa96 100644 +--- a/gcc/testsuite/gcc.target/loongarch/conditional-move-opt-1.c ++++ b/gcc/testsuite/gcc.target/loongarch/conditional-move-opt-1.c +@@ -27,7 +27,7 @@ void + test_lt () + { + if (lm < ln) +- lr *= (1 << 16); ++ lr += (1 << 16); + lr += lm; + } + +@@ -35,7 +35,7 @@ void + test_le () + { + if (lm <= ln) +- lr = lm * ((long)1 << 32); ++ lr = lm + ((long)1 << 32); + else + lr = lm; + lr += lm; +diff --git a/gcc/testsuite/gcc.target/loongarch/conditional-move-opt-2.c b/gcc/testsuite/gcc.target/loongarch/conditional-move-opt-2.c +index ac72d4d93..743fd5e67 100644 +--- a/gcc/testsuite/gcc.target/loongarch/conditional-move-opt-2.c ++++ b/gcc/testsuite/gcc.target/loongarch/conditional-move-opt-2.c +@@ -29,7 +29,7 @@ void + test_lez () + { + if (lm <= 0) +- lr &= (1 << 16); ++ lr |= (1 << 16); + lr += lm; + } + +diff --git a/gcc/testsuite/gcc.target/loongarch/conditional-move-opt-3.c b/gcc/testsuite/gcc.target/loongarch/conditional-move-opt-3.c +new file mode 100644 +index 000000000..95887980c +--- /dev/null ++++ b/gcc/testsuite/gcc.target/loongarch/conditional-move-opt-3.c +@@ -0,0 +1,14 @@ ++/* { dg-do compile } */ ++/* { dg-options "-O2" } */ ++/* { dg-final { scan-assembler "maskeqz" } } */ ++/* { dg-final { scan-assembler "masknez" } } */ ++ ++extern long lm, ln, lr; ++ ++void ++test_and () ++{ ++ if (lm < 0) ++ lr &= (1 << 16); ++ lr += lm; ++} +-- +2.51.1 + diff --git a/cross/gcc-riscv64/APKBUILD b/cross/gcc-riscv64/APKBUILD index 933df5bf9..b7cbf0c0a 100644 --- a/cross/gcc-riscv64/APKBUILD +++ b/cross/gcc-riscv64/APKBUILD @@ -34,7 +34,7 @@ _pkgsnap="${pkgver##*_git}" [ "$CHOST" != "$CTARGET" ] && _target="-$CTARGET_ARCH" || _target="" pkgname=gcc-riscv64 -pkgrel=1 +pkgrel=2 pkgdesc="Stage2 cross-compiler for riscv64" url="https://gcc.gnu.org" arch="x86_64" @@ -281,6 +281,7 @@ source="https://gcc.gnu.org/pub/gcc/releases/gcc-$_pkgbase/gcc-$_pkgbase.tar.xz 0041-ada-libgnat-recognize-linux-musleabi-and-linux-muslg.patch 0001-tree-object-size.cc-Fix-assert-constant-offset-in-ch.patch + 0001-LoongArch-Only-allow-valid-binary-op-when-optimize-c.patch " # secfixes: @@ -796,4 +797,5 @@ eecc77e2a9cf956fd752693ad7f8ff8253a7bb557e00564bb488bbc1deac895e63104cc1182a0bdd d166475e340c91bbb24cf257240aab37129b04f2609e5ce323b530ab83853a4c34c525e0072c15732717f1681db07e6b3b0a4d268720c31f460435ccf4c99b7f 0040-ada-libgnat-use-stub-symbolic-module-name-functions.patch c717764ef52c0226a23cbf434654cdefa6cbf38ec625648575d9143c5513b16d8914c25015db743033b8a46ac5b2c33ab75e1b67076128d67bb1319e5a83dd85 0041-ada-libgnat-recognize-linux-musleabi-and-linux-muslg.patch c3b64b05332bd4dd7fad3fff3cacd4f9de0512943f1548c6f1205fab1a74c83622024f30471805f57d625198cc32f647b32172914528fd5605d0bf61cb0c3ff1 0001-tree-object-size.cc-Fix-assert-constant-offset-in-ch.patch +e91873055550eba051d9297bec5c6acd27abb9ee6ce8911cdd04b5faf37d77b6b2a7607ec588d2863f13f14b48af9398cb4ac42443d8567bfa5037dc6bd50404 0001-LoongArch-Only-allow-valid-binary-op-when-optimize-c.patch " diff --git a/cross/gcc-x86/0001-LoongArch-Only-allow-valid-binary-op-when-optimize-c.patch b/cross/gcc-x86/0001-LoongArch-Only-allow-valid-binary-op-when-optimize-c.patch new file mode 100644 index 000000000..d10f4e51e --- /dev/null +++ b/cross/gcc-x86/0001-LoongArch-Only-allow-valid-binary-op-when-optimize-c.patch @@ -0,0 +1,130 @@ +From 824eae920f0f64dd7687c969a2436b129161fdc9 Mon Sep 17 00:00:00 2001 +From: Jinyang He +Date: Wed, 29 Oct 2025 16:07:35 +0800 +Subject: [PATCH] LoongArch: Only allow valid binary op when optimize + conditional move + +It is wrong that optimize from `if (cond) dest op= 1 << shift` to +`dest op= (cond ? 1 : 0) << shift` when `dest op 0 != dest`. +Like `and`, `mul` or `div`. +And in this optimization `mul` and `div` is optimized to shift. + +gcc/ChangeLog: + + * config/loongarch/loongarch.cc + (loongarch_expand_conditional_move): Only allow valid binary + op when optimize conditional move. + +gcc/testsuite/ChangeLog: + + * gcc.target/loongarch/conditional-move-opt-1.c: Remove mul. + * gcc.target/loongarch/conditional-move-opt-2.c: Remove and. + * gcc.target/loongarch/conditional-move-opt-3.c: New test. + +Co-Authored-By: Peng Fan +--- + gcc/config/loongarch/loongarch.cc | 26 ++++++++++++++++--- + .../loongarch/conditional-move-opt-1.c | 4 +-- + .../loongarch/conditional-move-opt-2.c | 2 +- + .../loongarch/conditional-move-opt-3.c | 14 ++++++++++ + 4 files changed, 40 insertions(+), 6 deletions(-) + create mode 100644 gcc/testsuite/gcc.target/loongarch/conditional-move-opt-3.c + +diff --git a/gcc/config/loongarch/loongarch.cc b/gcc/config/loongarch/loongarch.cc +index bdf290654..740c8611a 100644 +--- a/gcc/config/loongarch/loongarch.cc ++++ b/gcc/config/loongarch/loongarch.cc +@@ -5533,12 +5533,32 @@ loongarch_expand_conditional_move (rtx *operands) + } + } + ++ auto is_binary_op_0_keep_orig = [](enum rtx_code code) ++ { ++ switch (code) ++ { ++ case PLUS: ++ case MINUS: ++ case IOR: ++ case XOR: ++ case ROTATE: ++ case ROTATERT: ++ case ASHIFT: ++ case ASHIFTRT: ++ case LSHIFTRT: ++ return true; ++ default: ++ return false; ++ } ++ }; ++ + /* Check if the optimization conditions are met. */ + if (value_if_true_insn + && value_if_false_insn +- /* Make sure that value_if_false and var are the same. */ +- && BINARY_P (value_if_true_insn_src +- = SET_SRC (single_set (value_if_true_insn))) ++ /* Make sure that the orig value OP 0 keep orig. */ ++ && (value_if_true_insn_src ++ = SET_SRC (single_set (value_if_true_insn))) ++ && is_binary_op_0_keep_orig ( GET_CODE (value_if_true_insn_src)) + /* Make sure that both value_if_true and value_if_false + has the same var. */ + && rtx_equal_p (XEXP (value_if_true_insn_src, 0), +diff --git a/gcc/testsuite/gcc.target/loongarch/conditional-move-opt-1.c b/gcc/testsuite/gcc.target/loongarch/conditional-move-opt-1.c +index ed13471aa..47802aa96 100644 +--- a/gcc/testsuite/gcc.target/loongarch/conditional-move-opt-1.c ++++ b/gcc/testsuite/gcc.target/loongarch/conditional-move-opt-1.c +@@ -27,7 +27,7 @@ void + test_lt () + { + if (lm < ln) +- lr *= (1 << 16); ++ lr += (1 << 16); + lr += lm; + } + +@@ -35,7 +35,7 @@ void + test_le () + { + if (lm <= ln) +- lr = lm * ((long)1 << 32); ++ lr = lm + ((long)1 << 32); + else + lr = lm; + lr += lm; +diff --git a/gcc/testsuite/gcc.target/loongarch/conditional-move-opt-2.c b/gcc/testsuite/gcc.target/loongarch/conditional-move-opt-2.c +index ac72d4d93..743fd5e67 100644 +--- a/gcc/testsuite/gcc.target/loongarch/conditional-move-opt-2.c ++++ b/gcc/testsuite/gcc.target/loongarch/conditional-move-opt-2.c +@@ -29,7 +29,7 @@ void + test_lez () + { + if (lm <= 0) +- lr &= (1 << 16); ++ lr |= (1 << 16); + lr += lm; + } + +diff --git a/gcc/testsuite/gcc.target/loongarch/conditional-move-opt-3.c b/gcc/testsuite/gcc.target/loongarch/conditional-move-opt-3.c +new file mode 100644 +index 000000000..95887980c +--- /dev/null ++++ b/gcc/testsuite/gcc.target/loongarch/conditional-move-opt-3.c +@@ -0,0 +1,14 @@ ++/* { dg-do compile } */ ++/* { dg-options "-O2" } */ ++/* { dg-final { scan-assembler "maskeqz" } } */ ++/* { dg-final { scan-assembler "masknez" } } */ ++ ++extern long lm, ln, lr; ++ ++void ++test_and () ++{ ++ if (lm < 0) ++ lr &= (1 << 16); ++ lr += lm; ++} +-- +2.51.1 + diff --git a/cross/gcc-x86/APKBUILD b/cross/gcc-x86/APKBUILD index 0c664ba0f..d2b98ea1e 100644 --- a/cross/gcc-x86/APKBUILD +++ b/cross/gcc-x86/APKBUILD @@ -34,7 +34,7 @@ _pkgsnap="${pkgver##*_git}" [ "$CHOST" != "$CTARGET" ] && _target="-$CTARGET_ARCH" || _target="" pkgname=gcc-x86 -pkgrel=1 +pkgrel=2 pkgdesc="Stage2 cross-compiler for x86" url="https://gcc.gnu.org" arch="x86_64" @@ -281,6 +281,7 @@ source="https://gcc.gnu.org/pub/gcc/releases/gcc-$_pkgbase/gcc-$_pkgbase.tar.xz 0041-ada-libgnat-recognize-linux-musleabi-and-linux-muslg.patch 0001-tree-object-size.cc-Fix-assert-constant-offset-in-ch.patch + 0001-LoongArch-Only-allow-valid-binary-op-when-optimize-c.patch " # secfixes: @@ -796,4 +797,5 @@ eecc77e2a9cf956fd752693ad7f8ff8253a7bb557e00564bb488bbc1deac895e63104cc1182a0bdd d166475e340c91bbb24cf257240aab37129b04f2609e5ce323b530ab83853a4c34c525e0072c15732717f1681db07e6b3b0a4d268720c31f460435ccf4c99b7f 0040-ada-libgnat-use-stub-symbolic-module-name-functions.patch c717764ef52c0226a23cbf434654cdefa6cbf38ec625648575d9143c5513b16d8914c25015db743033b8a46ac5b2c33ab75e1b67076128d67bb1319e5a83dd85 0041-ada-libgnat-recognize-linux-musleabi-and-linux-muslg.patch c3b64b05332bd4dd7fad3fff3cacd4f9de0512943f1548c6f1205fab1a74c83622024f30471805f57d625198cc32f647b32172914528fd5605d0bf61cb0c3ff1 0001-tree-object-size.cc-Fix-assert-constant-offset-in-ch.patch +e91873055550eba051d9297bec5c6acd27abb9ee6ce8911cdd04b5faf37d77b6b2a7607ec588d2863f13f14b48af9398cb4ac42443d8567bfa5037dc6bd50404 0001-LoongArch-Only-allow-valid-binary-op-when-optimize-c.patch " diff --git a/cross/gcc-x86_64/0001-LoongArch-Only-allow-valid-binary-op-when-optimize-c.patch b/cross/gcc-x86_64/0001-LoongArch-Only-allow-valid-binary-op-when-optimize-c.patch new file mode 100644 index 000000000..d10f4e51e --- /dev/null +++ b/cross/gcc-x86_64/0001-LoongArch-Only-allow-valid-binary-op-when-optimize-c.patch @@ -0,0 +1,130 @@ +From 824eae920f0f64dd7687c969a2436b129161fdc9 Mon Sep 17 00:00:00 2001 +From: Jinyang He +Date: Wed, 29 Oct 2025 16:07:35 +0800 +Subject: [PATCH] LoongArch: Only allow valid binary op when optimize + conditional move + +It is wrong that optimize from `if (cond) dest op= 1 << shift` to +`dest op= (cond ? 1 : 0) << shift` when `dest op 0 != dest`. +Like `and`, `mul` or `div`. +And in this optimization `mul` and `div` is optimized to shift. + +gcc/ChangeLog: + + * config/loongarch/loongarch.cc + (loongarch_expand_conditional_move): Only allow valid binary + op when optimize conditional move. + +gcc/testsuite/ChangeLog: + + * gcc.target/loongarch/conditional-move-opt-1.c: Remove mul. + * gcc.target/loongarch/conditional-move-opt-2.c: Remove and. + * gcc.target/loongarch/conditional-move-opt-3.c: New test. + +Co-Authored-By: Peng Fan +--- + gcc/config/loongarch/loongarch.cc | 26 ++++++++++++++++--- + .../loongarch/conditional-move-opt-1.c | 4 +-- + .../loongarch/conditional-move-opt-2.c | 2 +- + .../loongarch/conditional-move-opt-3.c | 14 ++++++++++ + 4 files changed, 40 insertions(+), 6 deletions(-) + create mode 100644 gcc/testsuite/gcc.target/loongarch/conditional-move-opt-3.c + +diff --git a/gcc/config/loongarch/loongarch.cc b/gcc/config/loongarch/loongarch.cc +index bdf290654..740c8611a 100644 +--- a/gcc/config/loongarch/loongarch.cc ++++ b/gcc/config/loongarch/loongarch.cc +@@ -5533,12 +5533,32 @@ loongarch_expand_conditional_move (rtx *operands) + } + } + ++ auto is_binary_op_0_keep_orig = [](enum rtx_code code) ++ { ++ switch (code) ++ { ++ case PLUS: ++ case MINUS: ++ case IOR: ++ case XOR: ++ case ROTATE: ++ case ROTATERT: ++ case ASHIFT: ++ case ASHIFTRT: ++ case LSHIFTRT: ++ return true; ++ default: ++ return false; ++ } ++ }; ++ + /* Check if the optimization conditions are met. */ + if (value_if_true_insn + && value_if_false_insn +- /* Make sure that value_if_false and var are the same. */ +- && BINARY_P (value_if_true_insn_src +- = SET_SRC (single_set (value_if_true_insn))) ++ /* Make sure that the orig value OP 0 keep orig. */ ++ && (value_if_true_insn_src ++ = SET_SRC (single_set (value_if_true_insn))) ++ && is_binary_op_0_keep_orig ( GET_CODE (value_if_true_insn_src)) + /* Make sure that both value_if_true and value_if_false + has the same var. */ + && rtx_equal_p (XEXP (value_if_true_insn_src, 0), +diff --git a/gcc/testsuite/gcc.target/loongarch/conditional-move-opt-1.c b/gcc/testsuite/gcc.target/loongarch/conditional-move-opt-1.c +index ed13471aa..47802aa96 100644 +--- a/gcc/testsuite/gcc.target/loongarch/conditional-move-opt-1.c ++++ b/gcc/testsuite/gcc.target/loongarch/conditional-move-opt-1.c +@@ -27,7 +27,7 @@ void + test_lt () + { + if (lm < ln) +- lr *= (1 << 16); ++ lr += (1 << 16); + lr += lm; + } + +@@ -35,7 +35,7 @@ void + test_le () + { + if (lm <= ln) +- lr = lm * ((long)1 << 32); ++ lr = lm + ((long)1 << 32); + else + lr = lm; + lr += lm; +diff --git a/gcc/testsuite/gcc.target/loongarch/conditional-move-opt-2.c b/gcc/testsuite/gcc.target/loongarch/conditional-move-opt-2.c +index ac72d4d93..743fd5e67 100644 +--- a/gcc/testsuite/gcc.target/loongarch/conditional-move-opt-2.c ++++ b/gcc/testsuite/gcc.target/loongarch/conditional-move-opt-2.c +@@ -29,7 +29,7 @@ void + test_lez () + { + if (lm <= 0) +- lr &= (1 << 16); ++ lr |= (1 << 16); + lr += lm; + } + +diff --git a/gcc/testsuite/gcc.target/loongarch/conditional-move-opt-3.c b/gcc/testsuite/gcc.target/loongarch/conditional-move-opt-3.c +new file mode 100644 +index 000000000..95887980c +--- /dev/null ++++ b/gcc/testsuite/gcc.target/loongarch/conditional-move-opt-3.c +@@ -0,0 +1,14 @@ ++/* { dg-do compile } */ ++/* { dg-options "-O2" } */ ++/* { dg-final { scan-assembler "maskeqz" } } */ ++/* { dg-final { scan-assembler "masknez" } } */ ++ ++extern long lm, ln, lr; ++ ++void ++test_and () ++{ ++ if (lm < 0) ++ lr &= (1 << 16); ++ lr += lm; ++} +-- +2.51.1 + diff --git a/cross/gcc-x86_64/APKBUILD b/cross/gcc-x86_64/APKBUILD index 944fe9a66..a2a3347e1 100644 --- a/cross/gcc-x86_64/APKBUILD +++ b/cross/gcc-x86_64/APKBUILD @@ -34,7 +34,7 @@ _pkgsnap="${pkgver##*_git}" [ "$CHOST" != "$CTARGET" ] && _target="-$CTARGET_ARCH" || _target="" pkgname=gcc-x86_64 -pkgrel=1 +pkgrel=2 pkgdesc="Stage2 cross-compiler for x86_64" url="https://gcc.gnu.org" arch="aarch64" @@ -281,6 +281,7 @@ source="https://gcc.gnu.org/pub/gcc/releases/gcc-$_pkgbase/gcc-$_pkgbase.tar.xz 0041-ada-libgnat-recognize-linux-musleabi-and-linux-muslg.patch 0001-tree-object-size.cc-Fix-assert-constant-offset-in-ch.patch + 0001-LoongArch-Only-allow-valid-binary-op-when-optimize-c.patch " # secfixes: @@ -796,4 +797,5 @@ eecc77e2a9cf956fd752693ad7f8ff8253a7bb557e00564bb488bbc1deac895e63104cc1182a0bdd d166475e340c91bbb24cf257240aab37129b04f2609e5ce323b530ab83853a4c34c525e0072c15732717f1681db07e6b3b0a4d268720c31f460435ccf4c99b7f 0040-ada-libgnat-use-stub-symbolic-module-name-functions.patch c717764ef52c0226a23cbf434654cdefa6cbf38ec625648575d9143c5513b16d8914c25015db743033b8a46ac5b2c33ab75e1b67076128d67bb1319e5a83dd85 0041-ada-libgnat-recognize-linux-musleabi-and-linux-muslg.patch c3b64b05332bd4dd7fad3fff3cacd4f9de0512943f1548c6f1205fab1a74c83622024f30471805f57d625198cc32f647b32172914528fd5605d0bf61cb0c3ff1 0001-tree-object-size.cc-Fix-assert-constant-offset-in-ch.patch +e91873055550eba051d9297bec5c6acd27abb9ee6ce8911cdd04b5faf37d77b6b2a7607ec588d2863f13f14b48af9398cb4ac42443d8567bfa5037dc6bd50404 0001-LoongArch-Only-allow-valid-binary-op-when-optimize-c.patch "