From: Kyrill Tkachov <kyrylo.tkachov@arm.com>
To: GCC Patches <gcc-patches@gcc.gnu.org>
Cc: Ramana Radhakrishnan <ramana.radhakrishnan@arm.com>,
Richard Earnshaw <Richard.Earnshaw@arm.com>
Subject: [PATCH][ARM] PR 65694: Properly sign-extend large numbers before passing to GEN_INT in arm_canonicalize_comparison
Date: Fri, 10 Apr 2015 08:33:00 -0000 [thread overview]
Message-ID: <55278AC7.9070807@arm.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 1552 bytes --]
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 ends up in wide-int land the asserts there catch it and ICE. In this case it was 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 <kyrylo.tkachov@arm.com>
* 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 <kyrylo.tkachov@arm.com>
* g++.dg/torture/pr65694.C: New test.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: arm-extend-cmp.patch --]
[-- Type: text/x-patch; name=arm-extend-cmp.patch, Size: 6394 bytes --]
commit 90fbcc1f74efd4b5f077fa6caea91d24548cca34
Author: Kyrylo Tkachov <kyrylo.tkachov@arm.com>
Date: Wed Apr 8 17:08:17 2015 +0100
[ARM] PR target/65694: Use ARM_SIGN_EXTEND in arm_canonicalize_comparison
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 != maxval
&& arm_const_double_by_immediates (GEN_INT (i + 1)))
{
- *op1 = GEN_INT (i + 1);
+ *op1 = GEN_INT (trunc_int_for_mode (i + 1, DImode));
*code = *code == GT ? GE : LT;
return;
}
@@ -4994,7 +4994,7 @@ arm_canonicalize_comparison (int *code, rtx *op0, rtx *op1,
if (i != ~((unsigned HOST_WIDE_INT) 0)
&& arm_const_double_by_immediates (GEN_INT (i + 1)))
{
- *op1 = GEN_INT (i + 1);
+ *op1 = GEN_INT (trunc_int_for_mode (i + 1, DImode));
*code = *code == GTU ? GEU : LTU;
return;
}
@@ -5047,7 +5047,7 @@ arm_canonicalize_comparison (int *code, rtx *op0, rtx *op1,
if (i != maxval
&& (const_ok_for_arm (i + 1) || const_ok_for_arm (-(i + 1))))
{
- *op1 = GEN_INT (i + 1);
+ *op1 = GEN_INT (ARM_SIGN_EXTEND (i + 1));
*code = *code == GT ? GE : LT;
return;
}
@@ -5069,7 +5069,7 @@ arm_canonicalize_comparison (int *code, rtx *op0, rtx *op1,
if (i != ~((unsigned HOST_WIDE_INT) 0)
&& (const_ok_for_arm (i + 1) || const_ok_for_arm (-(i + 1))))
{
- *op1 = GEN_INT (i + 1);
+ *op1 = GEN_INT (ARM_SIGN_EXTEND (i + 1));
*code = *code == 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 <class _T1> struct B { _T1 first; };
+template <typename _Iterator, bool> struct C {
+ typedef typename _Iterator::iterator_type iterator_type;
+ static iterator_type _S_base(_Iterator p1) { return p1.base(); }
+};
+template <typename _RandomAccessIterator>
+typename _RandomAccessIterator::difference_type
+__distance(_RandomAccessIterator p1, _RandomAccessIterator p2, int) {
+ return p2 - p1;
+}
+
+template <typename _InputIterator>
+typename _InputIterator::difference_type distance(_InputIterator p1,
+ _InputIterator p2) {
+ return __distance(p1, p2, 0);
+}
+
+template <typename _Iterator, typename> class D {
+ _Iterator _M_current;
+
+public:
+ typedef _Iterator iterator_type;
+ typedef int difference_type;
+ _Iterator base() { return _M_current; }
+};
+
+template <typename _Iterator, typename _Container>
+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 = 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 <typename> class L : public G {};
+
+struct H {
+ static unsigned short *allocate(int p1) {
+ L<short> d;
+ d.allocate(p1);
+ }
+};
+struct I {
+ template <typename _InputIterator, typename _ForwardIterator>
+ 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<D<unsigned short *, int>, 1>::iterator_type
+__miter_base(D<unsigned short *, int> p1) {
+ return C<D<unsigned short *, int>, 1>::_S_base(p1);
+}
+
+template <bool, typename _II, typename _OI>
+_OI __copy_move_a(_II p1, _II p2, _OI p3) {
+ return F::__copy_m(p1, p2, p3);
+}
+
+template <bool _IsMove, typename _II, typename _OI>
+_OI __copy_move_a2(_II p1, _II p2, _OI p3) {
+ return __copy_move_a<_IsMove>(p1, p2, p3);
+}
+
+template <typename _II, typename _OI> _OI copy(_II p1, _II p2, _OI p3) {
+ C<D<unsigned short *, int>, 1>::iterator_type b, c = __miter_base(p1);
+ b = __miter_base(p2);
+ return __copy_move_a2<A::__value>(c, b, p3);
+}
+
+template <typename _InputIterator, typename _ForwardIterator>
+_ForwardIterator uninitialized_copy(_InputIterator p1, _InputIterator p2,
+ _ForwardIterator p3) {
+ return I::__uninit_copy(p1, p2, p3);
+}
+
+template <typename _InputIterator, typename _ForwardIterator, typename _Tp>
+_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 = int()) : _Base(p1, p2) {}
+ M(D<unsigned short *, int> p1, D<unsigned short *, int> p2) {
+ _M_initialize_dispatch(p1, p2, int());
+ }
+ D<pointer, int> begin();
+ D<pointer, int> end();
+ int size() { return _M_impl._M_finish - _M_impl._M_start; }
+ void _M_initialize_dispatch(D<unsigned short *, int> p1,
+ D<unsigned short *, int> p2, int) {
+ L<short> e;
+ int f = distance(p1, p2);
+ _M_impl._M_start = _M_allocate(f);
+ _M_impl._M_finish = __uninitialized_copy_a(p1, p2, _M_impl._M_start, e);
+ }
+};
+
+B<M> g, h;
+void twoMeans() {
+ M i(g.first.begin(), h.first.end());
+ M(i.size());
+}
next reply other threads:[~2015-04-10 8:33 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-04-10 8:33 Kyrill Tkachov [this message]
2015-04-10 8:57 ` Jakub Jelinek
2015-04-10 11:06 ` Kyrill Tkachov
2015-04-10 16:11 ` Jakub Jelinek
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=55278AC7.9070807@arm.com \
--to=kyrylo.tkachov@arm.com \
--cc=Richard.Earnshaw@arm.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=ramana.radhakrishnan@arm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).