This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[3.4 PATCH] PR opt/17853: -O2 ICE for MMX testcase
- From: Roger Sayle <roger at eyesopen dot com>
- To: gcc-patches at gcc dot gnu dot org, Mark Mitchell <mark at codesourcery dot com>
- Cc: Stuart Hastings <stuart at apple dot com>
- Date: Sun, 10 Oct 2004 10:49:55 -0600 (MDT)
- Subject: [3.4 PATCH] PR opt/17853: -O2 ICE for MMX testcase
The following patch is a fix for PR rtl-optimization/17853 suitable
for the gcc-3_4-branch. On mainline, the appropriate long term fix was
to provide the infrastructure for constant folding vector comparisons.
For the release branch, however, its probably better/safer to go
with Stuart Hastings' preference of just disabling the problematic
transformations.
It's interesting to observe that the recent clean-up of the RTL
optimizers on mainline means that this problematic transformation may
now be disabled at a single point. Unfortunately, for gcc 3.4.x, the
simplification of relational expressions is duplicated in (at least)
four places, all of which need to be touched by this patch.
The following patch has been tested against the gcc-3_4-branch on
i686-pc-linux-gnu with a full "make bootstrap", all default languages,
and regression tested with a top-level "make -k check" with no new
failures. The testcase below is identical to the one on mainline.
Ok for the gcc-3_4-branch?
2004-10-10 Roger Sayle <roger@eyesopen.com>
PR rtl-optimization/17853
* combine.c (combine_simplify_rtx): Don't attempt any simplifications
of vector mode comparison operators.
* cse.c (fold_rtx): Likewise.
* simplify-rtx.c (simplify_gen_relational): Avoid calling
simplify_relational_operation with vector mode comparison operators.
(simplify_rtx): Likewise.
2004-10-10 Stuart Hastings <stuart@apple.com>
Roger Sayle <roger@eyesopen.com>
PR rtl-optimization/17853
* gcc.dg/i386-mmx-5.c: New testcase.
Index: combine.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/combine.c,v
retrieving revision 1.400.4.9
diff -c -3 -p -r1.400.4.9 combine.c
*** combine.c 6 Jul 2004 21:12:12 -0000 1.400.4.9
--- combine.c 10 Oct 2004 15:17:16 -0000
*************** combine_simplify_rtx (rtx x, enum machin
*** 3715,3741 ****
temp = simplify_unary_operation (code, mode, XEXP (x, 0), op0_mode);
break;
case '<':
! {
! enum machine_mode cmp_mode = GET_MODE (XEXP (x, 0));
! if (cmp_mode == VOIDmode)
! {
! cmp_mode = GET_MODE (XEXP (x, 1));
! if (cmp_mode == VOIDmode)
! cmp_mode = op0_mode;
! }
! temp = simplify_relational_operation (code, cmp_mode,
! XEXP (x, 0), XEXP (x, 1));
! }
! #ifdef FLOAT_STORE_FLAG_VALUE
! if (temp != 0 && GET_MODE_CLASS (mode) == MODE_FLOAT)
{
! if (temp == const0_rtx)
! temp = CONST0_RTX (mode);
! else
! temp = CONST_DOUBLE_FROM_REAL_VALUE (FLOAT_STORE_FLAG_VALUE (mode),
! mode);
! }
#endif
break;
case 'c':
case '2':
--- 3715,3742 ----
temp = simplify_unary_operation (code, mode, XEXP (x, 0), op0_mode);
break;
case '<':
! if (! VECTOR_MODE_P (mode))
{
! enum machine_mode cmp_mode = GET_MODE (XEXP (x, 0));
! if (cmp_mode == VOIDmode)
! {
! cmp_mode = GET_MODE (XEXP (x, 1));
! if (cmp_mode == VOIDmode)
! cmp_mode = op0_mode;
! }
! temp = simplify_relational_operation (code, cmp_mode,
! XEXP (x, 0), XEXP (x, 1));
! #ifdef FLOAT_STORE_FLAG_VALUE
! if (temp != 0 && GET_MODE_CLASS (mode) == MODE_FLOAT)
! {
! if (temp == const0_rtx)
! temp = CONST0_RTX (mode);
! else
! temp = CONST_DOUBLE_FROM_REAL_VALUE
! (FLOAT_STORE_FLAG_VALUE (mode), mode);
! }
#endif
+ }
break;
case 'c':
case '2':
Index: cse.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cse.c,v
retrieving revision 1.278.4.6
diff -c -3 -p -r1.278.4.6 cse.c
*** cse.c 21 Jun 2004 23:32:58 -0000 1.278.4.6
--- cse.c 10 Oct 2004 15:17:18 -0000
*************** fold_rtx (rtx x, rtx insn)
*** 3868,3873 ****
--- 3868,3877 ----
break;
case '<':
+ /* Don't perform any simplifications of vector mode comparisons. */
+ if (VECTOR_MODE_P (mode))
+ break;
+
/* See what items are actually being compared and set FOLDED_ARG[01]
to those values and CODE to the actual comparison code. If any are
constant, set CONST_ARG0 and CONST_ARG1 appropriately. We needn't
Index: simplify-rtx.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/simplify-rtx.c,v
retrieving revision 1.172.4.2
diff -c -3 -p -r1.172.4.2 simplify-rtx.c
*** simplify-rtx.c 14 Jun 2004 17:48:02 -0000 1.172.4.2
--- simplify-rtx.c 10 Oct 2004 15:17:18 -0000
*************** simplify_gen_relational (enum rtx_code c
*** 204,210 ****
if (cmp_mode == VOIDmode)
cmp_mode = GET_MODE (op1);
! if (cmp_mode != VOIDmode)
{
tem = simplify_relational_operation (code, cmp_mode, op0, op1);
--- 204,211 ----
if (cmp_mode == VOIDmode)
cmp_mode = GET_MODE (op1);
! if (cmp_mode != VOIDmode
! && ! VECTOR_MODE_P (mode))
{
tem = simplify_relational_operation (code, cmp_mode, op0, op1);
*************** simplify_rtx (rtx x)
*** 3531,3536 ****
--- 3532,3539 ----
XEXP (x, 2));
case '<':
+ if (VECTOR_MODE_P (mode))
+ return NULL_RTX;
temp = simplify_relational_operation (code,
((GET_MODE (XEXP (x, 0))
!= VOIDmode)
/* PR rtl-optimization/17853 */
/* Contributed by Stuart Hastings <stuart@apple.com> */
/* { dg-do compile { target i?86-*-* x86_64-*-* } } */
/* { dg-options "-O2 -mmmx" } */
#include <mmintrin.h>
#include <stdlib.h>
__m64 global_mask;
int main()
{
__m64 zero = _mm_setzero_si64();
__m64 mask = _mm_cmpeq_pi8( zero, zero );
mask = _mm_unpacklo_pi8( mask, zero );
global_mask = mask;
return 0;
}
Roger
--
Roger Sayle, E-mail: roger@eyesopen.com
OpenEye Scientific Software, WWW: http://www.eyesopen.com/
Suite 1107, 3600 Cerrillos Road, Tel: (+1) 505-473-7385
Santa Fe, New Mexico, 87507. Fax: (+1) 505-473-0833