From: Stefan Schulze Frielinghaus <[email protected]>
During cprop we have to cost intermediate RTXs which may have
non-compare conditions as e.g. r108={(0x1)?r113:r109} which get folded
later on.
First seen with r16-5417-g97a7d568f3d720.
PR 125972
gcc/ChangeLog:
* config/s390/s390.cc (s390_rtx_costs): Deal with non-compare
conditions during costing. Also fix some indentation.
gcc/testsuite/ChangeLog:
* gcc.target/s390/pr125972.c: New test.
---
Once bootstrap+regtest finish I will push this patch.
gcc/config/s390/s390.cc | 15 ++++++++++++---
gcc/testsuite/gcc.target/s390/pr125972.c | 20 ++++++++++++++++++++
2 files changed, 32 insertions(+), 3 deletions(-)
create mode 100644 gcc/testsuite/gcc.target/s390/pr125972.c
diff --git a/gcc/config/s390/s390.cc b/gcc/config/s390/s390.cc
index 1bddd5e454a..d57499a48e6 100644
--- a/gcc/config/s390/s390.cc
+++ b/gcc/config/s390/s390.cc
@@ -3977,13 +3977,15 @@ s390_rtx_costs (rtx x, machine_mode mode, int
outer_code,
case MEM:
*total = 0;
return true;
- case SET: {
+ case SET:
+ {
rtx dst = SET_DEST (x);
rtx src = SET_SRC (x);
switch (GET_CODE (src))
{
- case IF_THEN_ELSE: {
+ case IF_THEN_ELSE:
+ {
/* Without this a conditional move instruction would be
accounted as 3 * COSTS_N_INSNS (set, if_then_else,
comparison operator). That's a bit pessimistic. */
@@ -3992,6 +3994,12 @@ s390_rtx_costs (rtx x, machine_mode mode, int outer_code,
return false;
rtx cond = XEXP (src, 0);
+ /* Intermediate RTXs may have a non-compare condition as e.g. a
+ constant like r108={(0x1)?r113:r109} which get folded later
+ on. */
+ if (GET_RTX_CLASS (GET_CODE (cond)) != RTX_COMPARE
+ && GET_RTX_CLASS (GET_CODE (cond)) != RTX_COMM_COMPARE)
+ return false;
if (!CC_REG_P (XEXP (cond, 0)) || !CONST_INT_P (XEXP (cond, 1)))
return false;
@@ -4050,7 +4058,8 @@ s390_rtx_costs (rtx x, machine_mode mode, int outer_code,
/* Otherwise just cost the src. */
*total += rtx_cost (src, mode, SET, 1, speed);
return true;
- case MEM: {
+ case MEM:
+ {
rtx address = XEXP (dst, 0);
rtx tmp;
HOST_WIDE_INT tmp2;
diff --git a/gcc/testsuite/gcc.target/s390/pr125972.c
b/gcc/testsuite/gcc.target/s390/pr125972.c
new file mode 100644
index 00000000000..a7180477c3b
--- /dev/null
+++ b/gcc/testsuite/gcc.target/s390/pr125972.c
@@ -0,0 +1,20 @@
+/* { dg-do compile { target int128 } } */
+/* { dg-options "-march=z16 -O3" } */
+
+int a, b, c;
+long d, e;
+int *f;
+__int128 g;
+void h() {
+ g = 0;
+ for (; g <= 33; ++g) {
+ int *i = &c;
+ *i = d - a;
+ if (*i) {
+ c = 0;
+ for (; c <= 8; ++c)
+ f = &b;
+ } else
+ ++e;
+ }
+}
--
2.54.0