Bug 54471 - [4.8 Regression] FAIL: gcc.dg/sms-8.c execution test
Summary: [4.8 Regression] FAIL: gcc.dg/sms-8.c execution test
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 4.8.0
: P3 normal
Target Milestone: 4.8.0
Assignee: Jakub Jelinek
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-09-03 17:58 UTC by John David Anglin
Modified: 2012-11-26 09:26 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2012-11-20 00:00:00


Attachments
Tree dump (269 bytes, text/plain)
2012-11-21 13:01 UTC, John David Anglin
Details
Tree dump (316 bytes, text/plain)
2012-11-21 13:02 UTC, John David Anglin
Details
gcc48-pr54471.patch (713 bytes, patch)
2012-11-21 14:42 UTC, Jakub Jelinek
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description John David Anglin 2012-09-03 17:58:11 UTC
Executing on host: /home/dave/gnu/gcc/objdir/gcc/xgcc -B/home/dave/gnu/gcc/objdir/gcc/ /home/dave/gnu/gcc/gcc/gcc/testsuite/gcc.dg/sms-8.c  -fno-diagnostics-show-caret   -O2 -fmodulo-sched -fmodulo-sched-allow-regmoves -fdump-rtl-sms --para
m sms-min-sc=1  -lm   -o ./sms-8.exe    (timeout = 300)spawn /home/dave/gnu/gcc/objdir/gcc/xgcc -B/home/dave/gnu/gcc/objdir/gcc/ /home/dave/gnu/gcc/gcc/gcc/testsuite/gcc.dg/sms-8.c -fno-diagnostics-show-caret -O2 -fmodulo-sched -fmodulo-sched-allow-regmoves -fdump-rtl-sms --param sms-min-sc=1 -
lm -o ./sms-8.exe
PASS: gcc.dg/sms-8.c (test for excess errors)Setting LD_LIBRARY_PATH to :/home/dave/gnu/gcc/objdir/gcc::/home/dave/gnu/gcc/objdir/gcc:/home/dave/gnu/gcc/objdir/hppa-linux-gnu/libstdc++-v3/src/.libs:/home/dave/gnu/gcc/objdir/hppa-linux-gnu/libmudflap/.libs:/home/dave/gnu/gcc/objdir/hppa-linux-gnu/libssp/.libs:/home/dave/gnu/gcc/objdir/hppa-linux-gnu/libgomp/.libs:/home/dave/gnu/gcc/objdir/hppa-linux-gnu/libatomic/.libs:/home/dave/gnu/gcc/objd
ir/./gcc:/home/dave/gnu/gcc/objdir/./prev-gcc
spawn [open ...]
FAIL: gcc.dg/sms-8.c execution test

(gdb) disass foo
Dump of assembler code for function foo:
   0x00010608 <+0>:	stw rp,-14(sp)
   0x0001060c <+4>:	ldo 40(sp),sp
=> 0x00010610 <+8>:	b,l 0x103e0,rp
   0x00010614 <+12>:	nop

foo is reduced to a call to abort by tree optimizers.
Comment 1 Jakub Jelinek 2012-11-20 12:06:16 UTC
Can't reproduce that with a cross.  The tree optimizers definitely don't optimize it into abort, and neither the assembly looks like what you are mentioning above.
Comment 2 dave.anglin 2012-11-21 02:26:56 UTC
On 20-Nov-12, at 7:06 AM, jakub at gcc dot gnu.org wrote:

> Can't reproduce that with a cross.  The tree optimizers definitely  
> don't
> optimize it into abort, and neither the assembly looks like what you  
> are
> mentioning above.

I'll recheck.  I definitely remember looking at the RTL from the  
expand pass.
That's why I marked it as a tree optimizer bug.

Dave
--
John David Anglin	dave.anglin@bell.net
Comment 3 John David Anglin 2012-11-21 13:01:33 UTC
Created attachment 28753 [details]
Tree dump
Comment 4 John David Anglin 2012-11-21 13:02:32 UTC
Created attachment 28754 [details]
Tree dump
Comment 5 John David Anglin 2012-11-21 13:13:22 UTC
Get the same with stage1 compiler.  Maybe this is a HWI32 issue?
Comment 6 Jakub Jelinek 2012-11-21 13:36:56 UTC
Reproduced with
extern void abort (void);

__attribute__ ((noinline))
unsigned __int128
foo (__int128 ixi, unsigned ctr)
{
  unsigned __int128 irslt = 1;
  __int128 ix = ixi;

  for (; ctr; ctr--)
    {
      irslt *= ix;
      ix *= ix;
    }

  if (irslt != 14348907)
    abort ();
  return irslt;
}

int
main ()
{
  unsigned __int128 res;

  res = foo (3, 4);
  return 0;
}

on x86_64-linux at -O2, seems to be a VRP bug.
Comment 7 Jakub Jelinek 2012-11-21 13:55:59 UTC
Caused by http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=190125
Comment 8 Jakub Jelinek 2012-11-21 14:42:13 UTC
Created attachment 28755 [details]
gcc48-pr54471.patch

Untested fix.  I believe the bug is in invalid canonicalization.  When
sizem1 is { -1, -1 } double_int, sizem1 + double_int_one is { 0, 0 }, as it wrapped, instead of { 0, 0, 1, 0 } quad_int.  And if min0 or min1 is zero, then
size - min{0,1} is also zero, and so is very likely smaller than max{0,1} (unless min{0,1} == max{0,1}), but we still don't want to "canonicalize" that to signed.  IMHO testing min2.is_zero () is sufficient, as min0 or min1 should be a valid double_int in the range 0 to { -1, -1 }, which is always smaller than the maximum unsigned integer + 1 in infinite precision and thus min2 should never be zero, unless size overflowed to 0 and min{0,1} is zero.
Comment 9 Marc Glisse 2012-11-21 17:18:47 UTC
Jakub, your patch makes sense to me (or min0.is_zero() and min1.is_zero()). I am ashamed I managed to get products with [0,n] (with n larger than MAX/2) wrong. Good thing Kenneth Zadeck's wide_int will soon allow us to remove most of this horrible code.

Another test that shows the error (optimizes away the call to g):

void g();
void h();
void f(unsigned __int128 x){
  if(x>(unsigned __int128)(-3))return;
  unsigned __int128 y=2*x;
  if(y==42) g();
  else h();
}
Comment 10 Jakub Jelinek 2012-11-21 17:31:58 UTC
Thanks, I'm going to include your test too then:
--- gcc/testsuite/gcc.dg/tree-ssa/vrp86.c.jj	2012-11-21 18:27:53.389280736 +0100
+++ gcc/testsuite/gcc.dg/tree-ssa/vrp86.c	2012-11-21 18:27:47.000000000 +0100
@@ -0,0 +1,26 @@
+/* PR tree-optimization/54471 */
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-vrp1" } */
+
+#ifdef __SIZEOF_INT128__
+#define T __int128
+#else
+#define T long long
+#endif
+
+void fn1call ();
+void fn2call ();
+void f (unsigned T x)
+{
+  if (x > (unsigned T) -3)
+    return;
+  unsigned T y = 2 * x;
+  if (y == 42)
+    fn1call ();
+  else
+    fn2call ();
+}
+
+/* { dg-final { scan-tree-dump "fn1call" "vrp1"} } */
+/* { dg-final { scan-tree-dump "fn2call" "vrp1"} } */
+/* { dg-final { cleanup-tree-dump "vrp1" } } */
Comment 11 Jakub Jelinek 2012-11-26 09:19:39 UTC
Author: jakub
Date: Mon Nov 26 09:19:30 2012
New Revision: 193806

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=193806
Log:
	PR tree-optimization/54471
	* tree-vrp.c (extract_range_from_binary_expr_1): For MULT_EXPR,
	don't canonicalize range if min2 is zero.

	* gcc.dg/tree-ssa/vrp86.c: New test.
	* gcc.c-torture/execute/pr54471.c: New test.

Added:
    trunk/gcc/testsuite/gcc.c-torture/execute/pr54471.c
    trunk/gcc/testsuite/gcc.dg/tree-ssa/vrp86.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/tree-vrp.c
Comment 12 Jakub Jelinek 2012-11-26 09:26:14 UTC
Fixed.