Bug 65170

Summary: [5 Regression] curve25519-donna-c64 miscompilation
Product: gcc Reporter: Sami Farin <hvtaifwkbgefbaei>
Component: tree-optimizationAssignee: Jakub Jelinek <jakub>
Status: RESOLVED FIXED    
Severity: major CC: jakub
Priority: P1    
Version: 5.0   
Target Milestone: 5.0   
Host: Target:
Build: Known to work:
Known to fail: Last reconfirmed: 2015-02-23 00:00:00
Attachments: curve25519-donna-c64.c
gcc5-pr65170.patch

Description Sami Farin 2015-02-23 09:59:40 UTC
Created attachment 34841 [details]
curve25519-donna-c64.c

curve25519-donna-c64.c function curve25519_donna with gcc-5.0.0-0.15.fc22,
flag -O3 , sets mypublic to all-zeros.
If I remove force_inline from fmul(), it compiles ok.
Could not produce a smaller test case.
Comment 1 Jakub Jelinek 2015-02-23 12:19:19 UTC
Started with r220164.  So, either the VR info before vrp2 pass is already wrong, or something goes wrong during the vrp2 pass.  Note the testcase uses TImode heavily.
Comment 2 Jakub Jelinek 2015-02-23 13:11:56 UTC
I believe this boils down to
__attribute__((noinline, noclone)) void
foo (__uint128_t b, __uint128_t c)
{
  __uint128_t a;
  b &= -1ULL;
  c &= -1ULL;
  a = b * c;
  if (a != 1)
    __builtin_abort ();
}

int
main ()
{
  foo (1, 1);
  return 0;
}
which at -O2 regressed with r210113 aka the wide-int merge.  Will look at it.
Comment 3 Jakub Jelinek 2015-02-23 15:39:25 UTC
Created attachment 34844 [details]
gcc5-pr65170.patch

Untested fix.
Comment 4 Jakub Jelinek 2015-02-24 08:07:41 UTC
Author: jakub
Date: Tue Feb 24 08:07:10 2015
New Revision: 220931

URL: https://gcc.gnu.org/viewcvs?rev=220931&root=gcc&view=rev
Log:
	PR tree-optimization/65170
	* wide-int.cc (wi::mul_internal): For the umul_ppmm optimization,
	if val[1] < 0, clear also val[2] and return 3.

	* gcc.c-torture/execute/pr65170.c: New test.
	* gcc.dg/tree-ssa/vrp96.c: New test.

Added:
    trunk/gcc/testsuite/gcc.c-torture/execute/pr65170.c
    trunk/gcc/testsuite/gcc.dg/tree-ssa/vrp96.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/wide-int.cc
    trunk/libsanitizer/ChangeLog
Comment 5 Jakub Jelinek 2015-02-24 08:21:54 UTC
Fixed now.