Hi David,

> I attempted to create a reproducer for PR 71779; however I'm not yet
> able to replicate the bogus cse reported there via the test case.

Thanks, this is just awesome.  I immediately had to try your patch.

The main reason for PR 71779 was that this

(insn 1047 1046 1048 (set (reg:DI 481)
        (subreg:DI (reg/f:SI 479) 0)) y.c:12702 -1
     (nil))

got transformed into that:

(insn 1047 1046 1048 107 (set (reg/f:DI 481)
        (subreg:DI (reg/f:SI 477) 0)) y.c:12702 50 {*movdi_aarch64}
     (expr_list:REG_DEAD (reg/f:SI 479)
        (nil)))

Note the "/f at reg 481.  This together with the fact that -mabi=ilp32
makes Pmode != ptr_mode caused a cascade of different errors.

For the wrong transformation in combine to happen, we need 
Pmode = DImode, ptr_mode=SImode, and REG_POINTER(x)
is true, but only REG_POINTER is really wrong.

First the good news.  The unit test does actually work, but not only
on aarch even without -mabi=ilp32, but also on i386.  All that's
missing is a check that we don't get a reg/f here:

test_pr71779 ()
{
  /* Only run this tests for target==aarch64.  */
#ifndef GCC_AARCH64_H
#ifndef I386_OPTS_H
  return;
#endif
#endif
  ...
  tem = cse_main (get_insns (), max_reg_num ());
  ASSERT_EQ (0, tem);
  ASSERT_FALSE (REG_POINTER (SET_DEST (PATTERN (get_insn_by_uid (1047)))));
}

Test fails on aarch64 and i386 if I revert the attached patch for PR 71779,
and passes again, if I apply the patch again.  Excellent!

Attached for your reference, the original patch file from PR 71779.

/home/ed/gnu/gcc-build-aarch64/./gcc/xgcc 
-B/home/ed/gnu/gcc-build-aarch64/./gcc/ -xc -S -c /dev/null -fself-test
../../gcc-trunk/gcc/cse.c:7872: test_pr71779: FAIL: ASSERT_FALSE 
(((__extension__ ({ __typeof (((((PATTERN (get_insn_by_uid 
(1047)))->u.fld[0]).rt_rtx))) const _rtx = (((((PATTERN (get_insn_by_uid 
(1047)))->u.fld[0]).rt_rtx))); if (((enum rtx_code) (_rtx)->code) != REG) 
rtl_check_failed_flag ("REG_POINTER", _rtx, "../../gcc-trunk/gcc/cse.c", 7872, 
__FUNCTION__); _rtx; })->frame_related)))
In function 'test_1':
cc1: internal compiler error: in fail, at selftest.c:46
0x11bdd8e selftest::fail(selftest::location const&, char const*)
        ../../gcc-trunk/gcc/selftest.c:46
0x10944ec test_pr71779
        ../../gcc-trunk/gcc/cse.c:7872
0x10944ec selftest::cse_c_tests()
        ../../gcc-trunk/gcc/cse.c:7881
0x11631fe selftest::run_tests()
        ../../gcc-trunk/gcc/selftest-run-tests.c:68
0xb36242 toplev::run_self_tests()
        ../../gcc-trunk/gcc/toplev.c:2074

I noticed, that ASSERT_FALSE does expand the macros, which makes
the output a bit hard to read.

One minor thing, an unrelated test did fail before the cse test got executed on 
my aarch64,
so I just commented that part out:


/home/ed/gnu/gcc-build-aarch64/./gcc/xgcc 
-B/home/ed/gnu/gcc-build-aarch64/./gcc/ -xc -S -c /dev/null -fself-test
../../gcc-trunk/gcc/read-rtl-function.c:923: test_loading_dump_fragment_2: 
FAIL: ASSERT_TRUE ((((lhs)->frame_related)))
In function 'test_1':
cc1: internal compiler error: in fail, at selftest.c:46
0x11be8ae selftest::fail(selftest::location const&, char const*)
        ../../gcc-trunk/gcc/selftest.c:46
0x115577a test_loading_dump_fragment_2
        ../../gcc-trunk/gcc/read-rtl-function.c:923
0x1157cce selftest::read_rtl_function_c_tests()
        ../../gcc-trunk/gcc/read-rtl-function.c:1183
0x1163d14 selftest::run_tests()
        ../../gcc-trunk/gcc/selftest-run-tests.c:66
0xb36262 toplev::run_self_tests()
        ../../gcc-trunk/gcc/toplev.c:2074


the aarch64 was configured this way:

../gcc-trunk/configure --prefix=/home/ed/gnu/aarch64-unknown-elf 
--target=aarch64-unknown-elf --enable-languages=c --disable-shared 
--disable-threads --disable-libssp --disable-libgomp --disable-libquadmath 
--disable-libatomic


Maybe one last comment on your patch itself, could you please move
the unit test cases in extra unit test files, or even a self-test tree?


Thanks
Bernd.
2016-08-04  Bernd Edlinger  <bernd.edlin...@hotmail.de>

	PR rtl-optimization/71779
	* emit-rtl.c (set_reg_attrs_from_value): Only propagate REG_POINTER,
	if the value was sign-extended according to POINTERS_EXTEND_UNSIGNED
	or if it was truncated.

Index: gcc/emit-rtl.c
===================================================================
--- gcc/emit-rtl.c	(revision 238915)
+++ gcc/emit-rtl.c	(working copy)
@@ -1156,7 +1156,11 @@ set_reg_attrs_from_value (rtx reg, rtx x)
     {
 #if defined(POINTERS_EXTEND_UNSIGNED)
       if (((GET_CODE (x) == SIGN_EXTEND && POINTERS_EXTEND_UNSIGNED)
-	   || (GET_CODE (x) != SIGN_EXTEND && ! POINTERS_EXTEND_UNSIGNED))
+	   || (GET_CODE (x) == ZERO_EXTEND && ! POINTERS_EXTEND_UNSIGNED)
+	   || (paradoxical_subreg_p (x)
+	       && ! (SUBREG_PROMOTED_VAR_P (x)
+		     && SUBREG_CHECK_PROMOTED_SIGN (x,
+						    POINTERS_EXTEND_UNSIGNED))))
 	  && !targetm.have_ptr_extend ())
 	can_be_reg_pointer = false;
 #endif

Reply via email to