Bug 64151 - [5 Regression] r218266 caused many regressions
Summary: [5 Regression] r218266 caused many regressions
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: rtl-optimization (show other bugs)
Version: 5.0
: P1 normal
Target Milestone: 5.0
Assignee: Not yet assigned to anyone
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2014-12-02 13:54 UTC by H.J. Lu
Modified: 2014-12-09 16:22 UTC (History)
1 user (show)

See Also:
Host:
Target: i686-linux
Build:
Known to work:
Known to fail:
Last reconfirmed: 2014-12-02 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description H.J. Lu 2014-12-02 13:54:49 UTC
On Linux/i686, r218266 caused:

FAIL: gcc.dg/hoist-register-pressure-3.c scan-rtl-dump hoist "PRE/HOIST: end of bb .* copying expression"
FAIL: gcc.dg/torture/stackalign/setjmp-1.c   -O1 -fpic execution test
FAIL: gcc.dg/torture/stackalign/setjmp-1.c   -O1 -mforce-drap -fpic execution test
FAIL: gcc.dg/torture/stackalign/setjmp-1.c   -O2 -flto -fno-use-linker-plugin -flto-partition=none -fpic execution test
FAIL: gcc.dg/torture/stackalign/setjmp-1.c   -O2 -flto -fno-use-linker-plugin -flto-partition=none -mforce-drap -fpic execution test
FAIL: gcc.dg/torture/stackalign/setjmp-1.c   -O2 -fpic execution test
FAIL: gcc.dg/torture/stackalign/setjmp-1.c   -O2 -mforce-drap -fpic execution test
FAIL: gcc.dg/torture/stackalign/setjmp-1.c   -O3 -fomit-frame-pointer -fpic execution test
FAIL: gcc.dg/torture/stackalign/setjmp-1.c   -O3 -fomit-frame-pointer -funroll-all-loops -finline-functions -fpic execution test
FAIL: gcc.dg/torture/stackalign/setjmp-1.c   -O3 -fomit-frame-pointer -funroll-all-loops -finline-functions -mforce-drap -fpic execution test
FAIL: gcc.dg/torture/stackalign/setjmp-1.c   -O3 -fomit-frame-pointer -funroll-loops -fpic execution test
FAIL: gcc.dg/torture/stackalign/setjmp-1.c   -O3 -fomit-frame-pointer -funroll-loops -mforce-drap -fpic execution test
FAIL: gcc.dg/torture/stackalign/setjmp-1.c   -O3 -fomit-frame-pointer -mforce-drap -fpic execution test
FAIL: gcc.dg/torture/stackalign/setjmp-1.c   -O3 -g -fpic execution test
FAIL: gcc.dg/torture/stackalign/setjmp-1.c   -O3 -g -mforce-drap -fpic execution test
FAIL: gcc.dg/torture/stackalign/setjmp-1.c   -Os -fpic execution test
FAIL: gcc.dg/torture/stackalign/setjmp-1.c   -Os -mforce-drap -fpic execution test
FAIL: gcc.dg/torture/stackalign/setjmp-3.c   -O1 -fpic execution test
FAIL: gcc.dg/torture/stackalign/setjmp-3.c   -O1 -mforce-drap -fpic execution test
FAIL: gcc.dg/torture/stackalign/setjmp-3.c   -O2 -flto -fno-use-linker-plugin -flto-partition=none -fpic execution test
FAIL: gcc.dg/torture/stackalign/setjmp-3.c   -O2 -flto -fno-use-linker-plugin -flto-partition=none -mforce-drap -fpic execution test
FAIL: gcc.dg/torture/stackalign/setjmp-3.c   -O2 -fpic execution test
FAIL: gcc.dg/torture/stackalign/setjmp-3.c   -O2 -mforce-drap -fpic execution test
FAIL: gcc.dg/torture/stackalign/setjmp-3.c   -O3 -fomit-frame-pointer -fpic execution test
FAIL: gcc.dg/torture/stackalign/setjmp-3.c   -O3 -fomit-frame-pointer -funroll-all-loops -finline-functions -fpic execution test
FAIL: gcc.dg/torture/stackalign/setjmp-3.c   -O3 -fomit-frame-pointer -funroll-all-loops -finline-functions -mforce-drap -fpic execution test
FAIL: gcc.dg/torture/stackalign/setjmp-3.c   -O3 -fomit-frame-pointer -funroll-loops -fpic execution test
FAIL: gcc.dg/torture/stackalign/setjmp-3.c   -O3 -fomit-frame-pointer -funroll-loops -mforce-drap -fpic execution test
FAIL: gcc.dg/torture/stackalign/setjmp-3.c   -O3 -fomit-frame-pointer -mforce-drap -fpic execution test
FAIL: gcc.dg/torture/stackalign/setjmp-3.c   -O3 -g -fpic execution test
FAIL: gcc.dg/torture/stackalign/setjmp-3.c   -O3 -g -mforce-drap -fpic execution test
FAIL: gcc.dg/torture/stackalign/setjmp-3.c   -Os -fpic execution test
FAIL: gcc.dg/torture/stackalign/setjmp-3.c   -Os -mforce-drap -fpic execution test
FAIL: gcc.dg/torture/stackalign/setjmp-4.c   -O1 -fpic execution test
FAIL: gcc.dg/torture/stackalign/setjmp-4.c   -O1 -mforce-drap -fpic execution test
FAIL: gcc.dg/torture/stackalign/setjmp-4.c   -O2 -flto -fno-use-linker-plugin -flto-partition=none -fpic execution test
FAIL: gcc.dg/torture/stackalign/setjmp-4.c   -O2 -flto -fno-use-linker-plugin -flto-partition=none -mforce-drap -fpic execution test
FAIL: gcc.dg/torture/stackalign/setjmp-4.c   -O2 -fpic execution test
FAIL: gcc.dg/torture/stackalign/setjmp-4.c   -O2 -mforce-drap -fpic execution test
FAIL: gcc.dg/torture/stackalign/setjmp-4.c   -O3 -fomit-frame-pointer -fpic execution test
FAIL: gcc.dg/torture/stackalign/setjmp-4.c   -O3 -fomit-frame-pointer -funroll-all-loops -finline-functions -fpic execution test
FAIL: gcc.dg/torture/stackalign/setjmp-4.c   -O3 -fomit-frame-pointer -funroll-all-loops -finline-functions -mforce-drap -fpic execution test
FAIL: gcc.dg/torture/stackalign/setjmp-4.c   -O3 -fomit-frame-pointer -funroll-loops -fpic execution test
FAIL: gcc.dg/torture/stackalign/setjmp-4.c   -O3 -fomit-frame-pointer -funroll-loops -mforce-drap -fpic execution test
FAIL: gcc.dg/torture/stackalign/setjmp-4.c   -O3 -fomit-frame-pointer -mforce-drap -fpic execution test
FAIL: gcc.dg/torture/stackalign/setjmp-4.c   -O3 -g -fpic execution test
FAIL: gcc.dg/torture/stackalign/setjmp-4.c   -O3 -g -mforce-drap -fpic execution test
FAIL: gcc.dg/torture/stackalign/setjmp-4.c   -Os -fpic execution test
FAIL: gcc.dg/torture/stackalign/setjmp-4.c   -Os -mforce-drap -fpic execution test
FAIL: gcc.target/i386/ifcvt-onecmpl-abs-1.c scan-assembler cltd
FAIL: gcc.target/i386/pr63527.c scan-assembler-not movl[ \t]%[^,]+, %ebx
FAIL: g++.dg/asan/asan_test.C   -O2  AddressSanitizer_BuiltinLongJmpTest execution test

when GCC is configured with

--with-arch=corei7 --with-cpu=intel --prefix=/usr/5.0.0 --enable-clocale=gnu --with-system-zlib --enable-shared --with-demangler-in-ld i686-linux --with-fpmath=sse --enable-languages=c,c++,fortran,java,lto,objc
Comment 1 H.J. Lu 2014-12-02 14:43:02 UTC
Revert the reg_class change:

diff --git a/gcc/ira-costs.c b/gcc/ira-costs.c
index 72c00cc..16fd6e8 100644
--- a/gcc/ira-costs.c
+++ b/gcc/ira-costs.c
@@ -1466,7 +1466,7 @@ scan_one_insn (rtx_insn *insn)
         && REG_N_SETS (REGNO (SET_DEST (set))) == 1))
       && general_operand (SET_SRC (set), GET_MODE (SET_SRC (set))))
     {
-      enum reg_class cl = ALL_REGS;
+      enum reg_class cl = GENERAL_REGS;
       rtx reg = SET_DEST (set);
       int num = COST_INDEX (REGNO (reg));

fixes those regressions.
Comment 2 Wilco 2014-12-02 21:22:36 UTC
(In reply to H.J. Lu from comment #1)
> Revert the reg_class change:
> 
> diff --git a/gcc/ira-costs.c b/gcc/ira-costs.c
> index 72c00cc..16fd6e8 100644
> --- a/gcc/ira-costs.c
> +++ b/gcc/ira-costs.c
> @@ -1466,7 +1466,7 @@ scan_one_insn (rtx_insn *insn)
>          && REG_N_SETS (REGNO (SET_DEST (set))) == 1))
>        && general_operand (SET_SRC (set), GET_MODE (SET_SRC (set))))
>      {
> -      enum reg_class cl = ALL_REGS;
> +      enum reg_class cl = GENERAL_REGS;
>        rtx reg = SET_DEST (set);
>        int num = COST_INDEX (REGNO (reg));
> 
> fixes those regressions.

Confirmed. The intention of this code is to account for reduced memory cost of constant loads - when they spill they do not need a store, but can be trivially rematerialized. What happens is that memory_move_cost returns 100 for certain cases on x86. With ALL_REGS the mem_cost then becomes very negative as it is not clamped to zero and this forces the register allocator to spill. This is bad as __builtin_longjmp on x86 loads EBP/ESP directly via 2 separate instructions which means reload *may* insert spill code inbetween. So if the base register is spilled and reloaded via EBP, it corrupts ESP:

        movl    -4(%ebp), %edx
        movl    (%edx), %ebp     * restore EBP
        movl    -4(%ebp), %ecx   * oops, this uses a different EBP
        movl    8(%ecx), %esp
        jmp     *%eax

I think there are cases where reload just gives up and inserts dumb spill code (ie. one reload per use), which means this issue can happen under other circumstances as well.

It appears ALL_REGS works for x86 and avoids the regression, however this is not correct either for FP or SIMD registers which would get 100 and then get spilled.
Comment 3 Markus Trippelsdorf 2014-12-02 21:33:42 UTC
See also PR64156 for the same issue on ppc64.
Comment 4 Igor Zamyatin 2014-12-03 12:32:26 UTC
I also see ~5% regression on eg spec2006/456.hmmer for i686 with -O3
Comment 5 hjl@gcc.gnu.org 2014-12-03 13:16:56 UTC
Author: hjl
Date: Wed Dec  3 13:16:25 2014
New Revision: 218312

URL: https://gcc.gnu.org/viewcvs?rev=218312&root=gcc&view=rev
Log:
Revert r218266

gcc/

	PR rtl-optimization/64151
	PR rtl-optimization/64156
	* ira-costs.c (scan_one_insn): Revert r218266.

gcc/testsuite/

	PR rtl-optimization/64151
	PR rtl-optimization/64156
	* gcc.target/aarch64/remat1.c: Removed.  Revert r218267.

Removed:
    trunk/gcc/testsuite/gcc.target/aarch64/remat1.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/ira-costs.c
    trunk/gcc/testsuite/ChangeLog
Comment 6 H.J. Lu 2014-12-03 13:20:27 UTC
Fixed.
Comment 7 Wilco 2014-12-09 16:22:17 UTC
See PR rtl-optimization/64242 for the longjmp issue on i386.