[Bug target/89506] [7/8/9 Regression] ICE: in decompose, at rtl.h:2266 with -Og -g

2019-03-02 Thread jakub at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89506

--- Comment #10 from Jakub Jelinek  ---
Author: jakub
Date: Sat Mar  2 08:05:10 2019
New Revision: 269339

URL: https://gcc.gnu.org/viewcvs?rev=269339&root=gcc&view=rev
Log:
PR target/89506
* config/arm/arm.md (cmpsi2_addneg): Use
trunc_int_for_mode (-INTVAL (...), SImode) instead of -INTVAL (...).
If operands[2] is 0 or INT_MIN, force use of subs.
(*compare_scc splitter): Use gen_int_mode.
(*negscc): Likewise.
* config/arm/thumb2.md (*thumb2_negscc): Likewise.

* gcc.dg/pr89506.c: New test.

Added:
trunk/gcc/testsuite/gcc.dg/pr89506.c
Modified:
trunk/gcc/ChangeLog
trunk/gcc/config/arm/arm.md
trunk/gcc/config/arm/thumb2.md
trunk/gcc/testsuite/ChangeLog

[Bug target/89506] [7/8/9 Regression] ICE: in decompose, at rtl.h:2266 with -Og -g

2019-02-27 Thread jakub at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89506

--- Comment #9 from Jakub Jelinek  ---
Using the expressions valgrind uses for ARM to compute flags from ADDS and SUBS
instructions and a program that simulates it on just 8-bit values instead of
32-bit ones, it seems the only problematic values where the flags change are 0
and INT_MIN.  By swapping the alternatives, I think the desirable one (subs)
should trigger for both, so the above patch should be hopefully correct.  Will
bootstrap/regtest it.

[Bug target/89506] [7/8/9 Regression] ICE: in decompose, at rtl.h:2266 with -Og -g

2019-02-27 Thread jakub at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89506

--- Comment #8 from Jakub Jelinek  ---
I meant adds r0, r0, #imm and subs r0, r0, #-imm of course.

[Bug target/89506] [7/8/9 Regression] ICE: in decompose, at rtl.h:2266 with -Og -g

2019-02-27 Thread jakub at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89506

--- Comment #7 from Jakub Jelinek  ---
Created attachment 45840
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=45840&action=edit
gcc9-pr89506.patch

If 0x8000 is the only immediate in which adds r0,r0,#imm and adds
r0,r0,#-imm differ in condition code flags settings, then we could just use
this patch.

[Bug target/89506] [7/8/9 Regression] ICE: in decompose, at rtl.h:2266 with -Og -g

2019-02-27 Thread jakub at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89506

--- Comment #6 from Jakub Jelinek  ---
int main () {
  for (long long j = -__INT_MAX__ - 1; j <= __INT_MAX__; j++)
{
  int t, t2, c, c2;
  int i = j;
  asm volatile ("adds %0, %2, #1; mrs %1, apsr" : "=r" (t), "=r" (c) : "r"
(i) : "cc");
  asm volatile ("subs %0, %2, %3; mrs %1, apsr" : "=r" (t2), "=r" (c2) :
"r" (i), "r" (-1) : "cc");
  if (t != t2 || c != c2)
__builtin_printf ("%d %d %d %d %d\n", i, t, t2, c, c2);
}
  return 0;
}

suggests though (unless I've screwed up something) that at least for the adds
r0, r0, #1 vs mvn r3, #0; subs r0, r0, r3 it doesn't make a difference.
On the other side,
int main () {
  for (long long j = -__INT_MAX__ - 1; j <= __INT_MAX__; j++)
{
  int t, t2, c, c2;
  int i = j;
  asm volatile ("adds %0, %2, #2147483648; mrs %1, apsr" : "=r" (t), "=r"
(c) : "r" (i) : "cc");
  asm volatile ("subs %0, %2, #2147483648; mrs %1, apsr" : "=r" (t2), "=r"
(c2) : "r" (i) : "cc");
  if (t != t2 || c != c2)
__builtin_printf ("%d %d %d %d %d\n", i, t, t2, c, c2);
}
  return 0;
}
triggers on lots of values.  If INT_MIN is the only problematic value, we could
tweak the patch to only handle that value carefully, or always emit subs
instead of adds for that case (e.g. by swapping the two alternatives).

[Bug target/89506] [7/8/9 Regression] ICE: in decompose, at rtl.h:2266 with -Og -g

2019-02-27 Thread jakub at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89506

--- Comment #5 from Jakub Jelinek  ---
Where we create larger code, it is:
(insn 7 6 8 2 (set (reg:SI 116)
(const_int -1 [0x])) "builtin-arith-overflow-1.c":11:1
181 {*arm_movsi_insn}
 (nil))
(insn 8 7 9 2 (parallel [
(set (reg:CC 100 cc)
(compare:CC (reg/v:SI 114 [ x ])
(reg:SI 116)))
(set (reg:SI 115)
(minus:SI (reg/v:SI 114 [ x ])
(reg:SI 116)))
]) "builtin-arith-overflow-1.c":11:1 28 {subsi3_compare1}
 (expr_list:REG_DEAD (reg:SI 116)
(expr_list:REG_DEAD (reg/v:SI 114 [ x ])
(nil
(jump_insn 9 8 12 2 (set (pc)
(if_then_else (ltu (reg:CC 100 cc)
(const_int 0 [0]))
(label_ref 12)
(pc))) "builtin-arith-overflow-1.c":11:1 203 {arm_cond_branch}
 (expr_list:REG_DEAD (reg:CC 100 cc)
(int_list:REG_BR_PROB 536868 (nil)))
where cprop previously managed to turn that subsi3_compare1 into cmpsi2_addneg,
but now it doesn't.  The question is, is
mvn r3, #0
subs r0, r0, r3
setting all the Z, N, C and V flags to the same values as
adds r0, r0, #1
for all the possible values of r0 or not?

And, should I split the
(*subsi3_carryin_compare_const): Similarly, just instead of -UINTVAL.
part of the patch to a separate, non-controversial, patch, to unbreak PR89434
fallout?

[Bug target/89506] [7/8/9 Regression] ICE: in decompose, at rtl.h:2266 with -Og -g

2019-02-27 Thread jakub at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89506

--- Comment #4 from Jakub Jelinek  ---
Created attachment 45838
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=45838&action=edit
gcc9-pr89506.patch

Untested version.

With this one, e.g. that t104_4ssub changes compared to vanilla:
-mov r3, #-2147483648
-subs r0, r0, r3
+subs r0, r0, #2147483648
so if that works, would be actually an improvement.
On the other side, there are some changes where the code is larger with the
patch:
-adds r0, r0, #1
+mvn r3, #0
+subs r0, r0, r3

[Bug target/89506] [7/8/9 Regression] ICE: in decompose, at rtl.h:2266 with -Og -g

2019-02-27 Thread jakub at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89506

Jakub Jelinek  changed:

   What|Removed |Added

 CC||ktkachov at gcc dot gnu.org,
   ||rearnsha at gcc dot gnu.org

--- Comment #3 from Jakub Jelinek  ---
I'm afraid I don't understand how the cmpsi2_cmpneg pattern can ever work
reliably.  It uses CCmode, so I think that means all of Z, N, C and V flags
have to be useful, but while the Z and N flags really don't care whether adds
or subs is used, I believe C and V depend on that heavily.
So, I'd understand cmpsi2_addneg pattern with CCmode that would only have the
subs alternative, and another pattern with CC_NOOVmode that would have both.

[Bug target/89506] [7/8/9 Regression] ICE: in decompose, at rtl.h:2266 with -Og -g

2019-02-27 Thread jakub at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89506

--- Comment #2 from Jakub Jelinek  ---
Unfortunately the patch regresses:
+FAIL: c-c++-common/torture/builtin-arith-overflow-1.c   -O2  execution test
+FAIL: c-c++-common/torture/builtin-arith-overflow-1.c   -O2 -flto
-fno-use-linker-plugin -flto-partition=none  execution test
+FAIL: c-c++-common/torture/builtin-arith-overflow-12.c   -O2  execution test
+FAIL: c-c++-common/torture/builtin-arith-overflow-12.c   -O2 -flto
-fno-use-linker-plugin -flto-partition=none  execution test
+FAIL: c-c++-common/torture/builtin-arith-overflow-13.c   -O2  execution test
+FAIL: c-c++-common/torture/builtin-arith-overflow-13.c   -O2 -flto
-fno-use-linker-plugin -flto-partition=none  execution test
+FAIL: c-c++-common/torture/builtin-arith-overflow-2.c   -O2  execution test
+FAIL: c-c++-common/torture/builtin-arith-overflow-2.c   -O2 -flto
-fno-use-linker-plugin -flto-partition=none  execution test
+FAIL: c-c++-common/torture/builtin-arith-overflow-p-12.c   -O2  execution test
+FAIL: c-c++-common/torture/builtin-arith-overflow-p-12.c   -O2 -flto
-fno-use-linker-plugin -flto-partition=none  execution test
+FAIL: c-c++-common/torture/builtin-arith-overflow-p-13.c   -O2  execution test
+FAIL: c-c++-common/torture/builtin-arith-overflow-p-13.c   -O2 -flto
-fno-use-linker-plugin -flto-partition=none  execution test

Looking at the first one, the differences are like:
 t104_4ssub:
@ args = 0, pretend = 0, frame = 0
@ frame_needed = 0, uses_anonymous_args = 0
-   mov r3, #-2147483648
-   subsr0, r0, r3
+   addsr0, r0, #-2147483648

[Bug target/89506] [7/8/9 Regression] ICE: in decompose, at rtl.h:2266 with -Og -g

2019-02-26 Thread rguenth at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89506

Richard Biener  changed:

   What|Removed |Added

   Priority|P3  |P2

[Bug target/89506] [7/8/9 Regression] ICE: in decompose, at rtl.h:2266 with -Og -g

2019-02-26 Thread jakub at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89506

Jakub Jelinek  changed:

   What|Removed |Added

 Status|NEW |ASSIGNED
   Assignee|unassigned at gcc dot gnu.org  |jakub at gcc dot gnu.org

--- Comment #1 from Jakub Jelinek  ---
Created attachment 45826
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=45826&action=edit
gcc9-pr89506.patch

Untested fix.

[Bug target/89506] [7/8/9 Regression] ICE: in decompose, at rtl.h:2266 with -Og -g

2019-02-26 Thread jakub at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89506

Jakub Jelinek  changed:

   What|Removed |Added

 Status|UNCONFIRMED |NEW
   Last reconfirmed||2019-02-26
 CC||jakub at gcc dot gnu.org
  Component|rtl-optimization|target
   Target Milestone|--- |7.5
 Ever confirmed|0   |1