From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 95985 invoked by alias); 10 Apr 2015 08:33:24 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 95969 invoked by uid 89); 10 Apr 2015 08:33:23 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.8 required=5.0 tests=AWL,BAYES_00,SPF_PASS autolearn=ham version=3.3.2 X-HELO: eu-smtp-delivery-143.mimecast.com Received: from eu-smtp-delivery-143.mimecast.com (HELO eu-smtp-delivery-143.mimecast.com) (207.82.80.143) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 10 Apr 2015 08:33:21 +0000 Received: from cam-owa2.Emea.Arm.com (fw-tnat.cambridge.arm.com [217.140.96.140]) by uk-mta-8.uk.mimecast.lan; Fri, 10 Apr 2015 09:33:18 +0100 Received: from [10.2.207.50] ([10.1.2.79]) by cam-owa2.Emea.Arm.com with Microsoft SMTPSVC(6.0.3790.3959); Fri, 10 Apr 2015 09:33:17 +0100 Message-ID: <55278AC7.9070807@arm.com> Date: Fri, 10 Apr 2015 08:33:00 -0000 From: Kyrill Tkachov User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.2.0 MIME-Version: 1.0 To: GCC Patches CC: Ramana Radhakrishnan , Richard Earnshaw Subject: [PATCH][ARM] PR 65694: Properly sign-extend large numbers before passing to GEN_INT in arm_canonicalize_comparison X-MC-Unique: th4coADPSDez4dwvjwIBxQ-1 Content-Type: multipart/mixed; boundary="------------010204090901030202020909" X-IsSubscribed: yes X-SW-Source: 2015-04/txt/msg00437.txt.bz2 This is a multi-part message in MIME format. --------------010204090901030202020909 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable Content-length: 1508 Hi all, This ICE has a similar cause to PR 64600. The arm backend creates a const_int with a large value and doesn't properly= sign-extend it. If that rtx then happens to pass through the simplify-rtx machinery and end= s up in wide-int land the asserts there catch it and ICE. In this case it w= as 0x7fffffff having 1 added to it to make 0x80000000 which should have been sign-extended to 0xffffffff80000000. The code that caused this is: class G { public: void allocate(int p1) { if (p1 > max_size()) operator new(sizeof(short)); } unsigned max_size() { return -1 / sizeof(short); } }; but it also needs to go through simplify-rtx to ICE, so the testcase contains the context as well. Similarly, the solution here is to use ARM_SIGN_EXTEND on the SImode constants and trunc_int_for_mode for the DImode ones. Bootstrapped and tested on arm-none-linux-gnueabihf. Built SPEC2006 with it. No code changes anywhere except in one instruction where a: cmp r6, #2147483648 is transformed into a: cmp r6, #-2147483648 Both assemble to the same thing, the disassembly is: cmp.w r6, #2147483648 ; 0x80000000 Ok for trunk? Thanks, Kyrill 2015-04-09 Kyrylo Tkachov * config/arm/arm.c (arm_canonicalize_comparison): Use ARM_SIGN_EXTEND when creating +1 values for SImode and trunc_int_for_mode for similar DImode operations. 2015-04-09 Kyrylo Tkachov * g++.dg/torture/pr65694.C: New test. --------------010204090901030202020909 Content-Type: text/x-patch; name=arm-extend-cmp.patch Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="arm-extend-cmp.patch" Content-length: 6278 commit 90fbcc1f74efd4b5f077fa6caea91d24548cca34 Author: Kyrylo Tkachov Date: Wed Apr 8 17:08:17 2015 +0100 [ARM] PR target/65694: Use ARM_SIGN_EXTEND in arm_canonicalize_comparis= on diff --git a/gcc/config/arm/arm.c b/gcc/config/arm/arm.c index 369cb67..5342b33 100644 --- a/gcc/config/arm/arm.c +++ b/gcc/config/arm/arm.c @@ -4984,7 +4984,7 @@ arm_canonicalize_comparison (int *code, rtx *op0, rtx= *op1, if (i !=3D maxval && arm_const_double_by_immediates (GEN_INT (i + 1))) { - *op1 =3D GEN_INT (i + 1); + *op1 =3D GEN_INT (trunc_int_for_mode (i + 1, DImode)); *code =3D *code =3D=3D GT ? GE : LT; return; } @@ -4994,7 +4994,7 @@ arm_canonicalize_comparison (int *code, rtx *op0, rtx= *op1, if (i !=3D ~((unsigned HOST_WIDE_INT) 0) && arm_const_double_by_immediates (GEN_INT (i + 1))) { - *op1 =3D GEN_INT (i + 1); + *op1 =3D GEN_INT (trunc_int_for_mode (i + 1, DImode)); *code =3D *code =3D=3D GTU ? GEU : LTU; return; } @@ -5047,7 +5047,7 @@ arm_canonicalize_comparison (int *code, rtx *op0, rtx= *op1, if (i !=3D maxval && (const_ok_for_arm (i + 1) || const_ok_for_arm (-(i + 1)))) { - *op1 =3D GEN_INT (i + 1); + *op1 =3D GEN_INT (ARM_SIGN_EXTEND (i + 1)); *code =3D *code =3D=3D GT ? GE : LT; return; } @@ -5069,7 +5069,7 @@ arm_canonicalize_comparison (int *code, rtx *op0, rtx= *op1, if (i !=3D ~((unsigned HOST_WIDE_INT) 0) && (const_ok_for_arm (i + 1) || const_ok_for_arm (-(i + 1)))) { - *op1 =3D GEN_INT (i + 1); + *op1 =3D GEN_INT (ARM_SIGN_EXTEND (i + 1)); *code =3D *code =3D=3D GTU ? GEU : LTU; return; } diff --git a/gcc/testsuite/g++.dg/torture/pr65694.C b/gcc/testsuite/g++.dg/= torture/pr65694.C new file mode 100644 index 0000000..55e009a --- /dev/null +++ b/gcc/testsuite/g++.dg/torture/pr65694.C @@ -0,0 +1,144 @@ +/* { dg-do compile } */ +/* { dg-options "-Wno-sign-compare -Wno-return-type -Wno-overflow" } */ +/* { dg-additional-options "-mthumb" { target arm_thumb2_ok } } */ + +struct A { + enum { __value }; +}; +template struct B { _T1 first; }; +template struct C { + typedef typename _Iterator::iterator_type iterator_type; + static iterator_type _S_base(_Iterator p1) { return p1.base(); } +}; +template +typename _RandomAccessIterator::difference_type +__distance(_RandomAccessIterator p1, _RandomAccessIterator p2, int) { + return p2 - p1; +} + +template +typename _InputIterator::difference_type distance(_InputIterator p1, + _InputIterator p2) { + return __distance(p1, p2, 0); +} + +template class D { + _Iterator _M_current; + +public: + typedef _Iterator iterator_type; + typedef int difference_type; + _Iterator base() { return _M_current; } +}; + +template +typename D<_Iterator, _Container>::difference_type +operator-(D<_Iterator, _Container> p1, D<_Iterator, _Container> p2) { + return p1.base() - p2.base(); +} + +struct F { + static unsigned short *__copy_m(unsigned short *p1, unsigned short *p2, + unsigned short *p3) { + int a =3D p2 - p1; + if (a) + __builtin_memmove(p3, p1, a); + return p3 + a; + } +}; +class G { +public: + void allocate(int p1) { + if (p1 > max_size()) + operator new(sizeof(short)); + } + unsigned max_size() { return -1 / sizeof(short); } +}; + +template class L : public G {}; + +struct H { + static unsigned short *allocate(int p1) { + L d; + d.allocate(p1); + } +}; +struct I { + template + static _ForwardIterator __uninit_copy(_InputIterator p1, _InputIterator = p2, + _ForwardIterator p3) { + return copy(p1, p2, p3); + } +}; +struct J { + typedef unsigned short *pointer; + struct K { + unsigned short *_M_start; + unsigned short *_M_finish; + }; + J(); + J(int p1, int) { _M_create_storage(p1); } + K _M_impl; + pointer _M_allocate(unsigned p1) { p1 ? H::allocate(p1) : pointer(); } + void _M_create_storage(int p1) { _M_allocate(p1); } +}; + +C, 1>::iterator_type +__miter_base(D p1) { + return C, 1>::_S_base(p1); +} + +template +_OI __copy_move_a(_II p1, _II p2, _OI p3) { + return F::__copy_m(p1, p2, p3); +} + +template +_OI __copy_move_a2(_II p1, _II p2, _OI p3) { + return __copy_move_a<_IsMove>(p1, p2, p3); +} + +template _OI copy(_II p1, _II p2, _OI p3) { + C, 1>::iterator_type b, c =3D __miter_base(p1); + b =3D __miter_base(p2); + return __copy_move_a2(c, b, p3); +} + +template +_ForwardIterator uninitialized_copy(_InputIterator p1, _InputIterator p2, + _ForwardIterator p3) { + return I::__uninit_copy(p1, p2, p3); +} + +template +_ForwardIterator __uninitialized_copy_a(_InputIterator p1, _InputIterator = p2, + _ForwardIterator p3, L<_Tp>) { + return uninitialized_copy(p1, p2, p3); +} + +class M : J { + J _Base; + +public: + M(); + M(int p1, int p2 =3D int()) : _Base(p1, p2) {} + M(D p1, D p2) { + _M_initialize_dispatch(p1, p2, int()); + } + D begin(); + D end(); + int size() { return _M_impl._M_finish - _M_impl._M_start; } + void _M_initialize_dispatch(D p1, + D p2, int) { + L e; + int f =3D distance(p1, p2); + _M_impl._M_start =3D _M_allocate(f); + _M_impl._M_finish =3D __uninitialized_copy_a(p1, p2, _M_impl._M_start,= e); + } +}; + +B g, h; +void twoMeans() { + M i(g.first.begin(), h.first.end()); + M(i.size()); +} --------------010204090901030202020909--