Bug 61092 - [4.10 Regression]: wide-int merge broke alpha bootstrap
Summary: [4.10 Regression]: wide-int merge broke alpha bootstrap
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 5.0
: P3 normal
Target Milestone: 4.9.1
Assignee: Uroš Bizjak
URL:
Keywords: build
Depends on:
Blocks:
 
Reported: 2014-05-07 06:50 UTC by Uroš Bizjak
Modified: 2014-05-09 15:06 UTC (History)
2 users (show)

See Also:
Host:
Target: alphaev68-pc-linux-gnu
Build:
Known to work:
Known to fail:
Last reconfirmed: 2014-05-08 00:00:00


Attachments
Preprocessed source (89.94 KB, application/x-bzip2)
2014-05-07 06:55 UTC, Uroš Bizjak
Details
Proposed patch that implements TARGET_GIMPLE_FOLD_BUILTIN for alpha (989 bytes, patch)
2014-05-07 21:42 UTC, Uroš Bizjak
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Uroš Bizjak 2014-05-07 06:50:15 UTC
/home/uros/gcc-build/./prev-gcc/xg++ -B/home/uros/gcc-build/./prev-gcc/ -B/usr/local/alphaev68-unknown-linux-gnu/bin/ -nostdinc++ -B/home/uros/gcc-build/prev-alphaev68-unknown-linux-gnu/libstdc++-v3/src/.libs -B/home/uros/gcc-build/prev-alphaev68-unknown-linux-gnu/libstdc++-v3/libsupc++/.libs  -I/home/uros/gcc-build/prev-alphaev68-unknown-linux-gnu/libstdc++-v3/include/alphaev68-unknown-linux-gnu  -I/home/uros/gcc-build/prev-alphaev68-unknown-linux-gnu/libstdc++-v3/include  -I/home/uros/gcc-svn/trunk/libstdc++-v3/libsupc++ -L/home/uros/gcc-build/prev-alphaev68-unknown-linux-gnu/libstdc++-v3/src/.libs -L/home/uros/gcc-build/prev-alphaev68-unknown-linux-gnu/libstdc++-v3/libsupc++/.libs -c   -g -O2 -gtoggle -DIN_GCC    -fno-exceptions -fno-rtti -fasynchronous-unwind-tables -W -Wall -Wno-narrowing -Wwrite-strings -Wcast-qual -Wmissing-format-attribute -Woverloaded-virtual -pedantic -Wno-long-long -Wno-variadic-macros -Wno-overlength-strings -Werror -fno-common  -DHAVE_CONFIG_H -I. -I. -I../../gcc-svn/trunk/gcc -I../../gcc-svn/trunk/gcc/. -I../../gcc-svn/trunk/gcc/../include -I../../gcc-svn/trunk/gcc/../libcpp/include  -I../../gcc-svn/trunk/gcc/../libdecnumber -I../../gcc-svn/trunk/gcc/../libdecnumber/dpd -I../libdecnumber -I../../gcc-svn/trunk/gcc/../libbacktrace    -o wide-int.o -MT wide-int.o -MMD -MP -MF ./.deps/wide-int.TPo ../../gcc-svn/trunk/gcc/wide-int.cc
In file included from ../../gcc-svn/trunk/gcc/wide-int.cc:37:0:
../../gcc-svn/trunk/gcc/wide-int.cc: In function ‘unsigned int wi::mul_internal(long int*, const long int*, unsigned int, const long int*, unsigned int, unsigned int, signop, bool*, bool)’:
../../gcc-svn/trunk/gcc/../include/longlong.h:145:10: sorry, unimplemented: unexpected AST of kind mult_highpart_expr
     (ph) = __builtin_alpha_umulh (__m0, __m1);    \
          ^
../../gcc-svn/trunk/gcc/wide-int.cc:1269:4: note: in expansion of macro ‘umul_ppmm’
    umul_ppmm (val[1], val[0], op1.ulow (), op2.ulow ());
    ^
../../gcc-svn/trunk/gcc/../include/longlong.h:145:10: internal compiler error: in potential_constant_expression_1, at cp/semantics.c:10575
     (ph) = __builtin_alpha_umulh (__m0, __m1);    \
          ^
../../gcc-svn/trunk/gcc/wide-int.cc:1269:4: note: in expansion of macro ‘umul_ppmm’
    umul_ppmm (val[1], val[0], op1.ulow (), op2.ulow ());
    ^
0x12047846f potential_constant_expression_1
        ../../gcc-svn/trunk/gcc/cp/semantics.c:10575
0x1204784bb potential_constant_expression(tree_node*)
        ../../gcc-svn/trunk/gcc/cp/semantics.c:10585
0x12047555f maybe_constant_value(tree_node*)
        ../../gcc-svn/trunk/gcc/cp/semantics.c:9930
0x1203e9e3f cp_convert_and_check(tree_node*, tree_node*, int)
        ../../gcc-svn/trunk/gcc/cp/cvt.c:630
0x1201819d7 convert_like_real
        ../../gcc-svn/trunk/gcc/cp/call.c:6345
0x1201925af perform_implicit_conversion_flags(tree_node*, tree_node*, int, int)
        ../../gcc-svn/trunk/gcc/cp/call.c:9109
0x1203dffb3 convert_for_assignment
        ../../gcc-svn/trunk/gcc/cp/typeck.c:8163
...
Comment 1 Uroš Bizjak 2014-05-07 06:55:45 UTC
Created attachment 32751 [details]
Preprocessed source

Fails with -O2.
Comment 2 Uroš Bizjak 2014-05-07 07:11:58 UTC
The failure can be triggered with an attached precompiled source using a crosscompiler from x86-64 to alphaev68-pc-linux-gnu, with -O2:

~/gcc-build-xxx/gcc/cc1plus -O2 -quiet wide-int.ii 
cc1plus: error: no include path in which to search for stdc-predef.h
../../gcc-svn/trunk/gcc/wide-int.cc: In function ‘unsigned int wi::mul_internal(long int*, const long int*, unsigned int, const long int*, unsigned int, unsigned int, signop, bool*, bool)’:
../../gcc-svn/trunk/gcc/wide-int.cc:1269:70: sorry, unimplemented: unexpected AST of kind mult_highpart_expr
../../gcc-svn/trunk/gcc/wide-int.cc:1269:70: internal compiler error: in potential_constant_expression_1, at cp/semantics.c:10575
0x6a1a3f potential_constant_expression_1
        ../../gcc-svn/trunk/gcc/cp/semantics.c:10575
0x6a9c2c potential_constant_expression(tree_node*)
        ../../gcc-svn/trunk/gcc/cp/semantics.c:10585
0x6a9cb3 maybe_constant_value(tree_node*)
        ../../gcc-svn/trunk/gcc/cp/semantics.c:9927
...
Comment 3 Jakub Jelinek 2014-05-07 08:02:02 UTC
If I remember well, this sounds like a problem that has been seen on aarch64 in the past:
http://gcc.gnu.org/ml/gcc-patches/2013-04/msg00586.html
(and the whole thread)
http://gcc.gnu.org/ml/gcc-patches/2013-04/msg01503.html
So, this looks like an alpha backend bug, where it should do some (or all?) the foldings of md builtins in gimple_fold_builtin hook rather than fold_builtin.
Comment 4 Uroš Bizjak 2014-05-07 09:52:43 UTC
Jakub, what do you think about following c++ patch:

--cut here--
Index: semantics.c
===================================================================
--- semantics.c (revision 210137)
+++ semantics.c (working copy)
@@ -9630,6 +9630,7 @@ cxx_eval_constant_expression (const constexpr_call
     case PLUS_EXPR:
     case MINUS_EXPR:
     case MULT_EXPR:
+    case MULT_HIGHPART_EXPR:
     case TRUNC_DIV_EXPR:
     case CEIL_DIV_EXPR:
     case FLOOR_DIV_EXPR:
@@ -10484,6 +10485,7 @@ potential_constant_expression_1 (tree t, bool want
 
     case PLUS_EXPR:
     case MULT_EXPR:
+    case MULT_HIGHPART_EXPR:
     case POINTER_PLUS_EXPR:
     case RDIV_EXPR:
     case EXACT_DIV_EXPR:
--cut here--

This patch fixes the compilation of the testcase and allows native alpha bootstrap to continue.
Comment 5 Jakub Jelinek 2014-05-07 10:08:39 UTC
See the discussions, this is a step in a bad direction, the backend builtins should be folded only during gimplification (i.e. the gimple_fold_builtin targhook), unless folding them is required e.g. for C++11 constexprs etc.
If folding them is solely an optimization or implementation of those builtins, then the FE should see them just as calls and only later on they should be folded.
Comment 6 Richard Biener 2014-05-07 13:03:11 UTC
IMHO fold_builtin should go away entirely in favor of gimple_fold_builtin.
Comment 7 Uroš Bizjak 2014-05-07 21:42:19 UTC
Created attachment 32757 [details]
Proposed patch that implements TARGET_GIMPLE_FOLD_BUILTIN for alpha

I am testing the attached patch.
Comment 8 Uroš Bizjak 2014-05-08 15:27:00 UTC
Patch at [1].

[1] http://gcc.gnu.org/ml/gcc-patches/2014-05/msg00493.html
Comment 9 uros 2014-05-08 19:02:59 UTC
Author: uros
Date: Thu May  8 19:02:28 2014
New Revision: 210233

URL: http://gcc.gnu.org/viewcvs?rev=210233&root=gcc&view=rev
Log:
	PR target/61092
	* config/alpha/alpha.c: Include gimple-iterator.h.
	(alpha_gimple_fold_builtin): New function.  Move
	ALPHA_BUILTIN_UMULH folding from ...
	(alpha_fold_builtin): ... here.
	(TARGET_GIMPLE_FOLD_BUILTIN): New define.


Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/config/alpha/alpha.c
Comment 10 uros 2014-05-09 15:02:41 UTC
Author: uros
Date: Fri May  9 15:02:09 2014
New Revision: 210278

URL: http://gcc.gnu.org/viewcvs?rev=210278&root=gcc&view=rev
Log:
	Backport from mainline
	2014-05-08  Uros Bizjak  <ubizjak@gmail.com>

	PR target/61092
	* config/alpha/alpha.c: Include gimple-iterator.h.
	(alpha_gimple_fold_builtin): New function.  Move
	ALPHA_BUILTIN_UMULH folding from ...
	(alpha_fold_builtin): ... here.
	(TARGET_GIMPLE_FOLD_BUILTIN): New define.


Modified:
    branches/gcc-4_9-branch/gcc/ChangeLog
    branches/gcc-4_9-branch/gcc/config/alpha/alpha.c
Comment 11 Uroš Bizjak 2014-05-09 15:06:32 UTC
Fixed.