From 3b96e89dd8e8c20bdc8cbd7dbccf15e84df36dca Mon Sep 17 00:00:00 2001 From: Uros Bizjak Date: Thu, 23 May 2019 06:55:40 +0200 Subject: [PATCH] backport: re PR target/90547 (ICE in gen_lowpart_general, at rtlhooks.c:63) MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Backported from mainline 2019-05-21 Uroš Bizjak * config/i386/cpuid.h (__cpuid): For 32bit targets, zero %ebx and %ecx bafore calling cpuid with leaf 1 or non-constant leaf argument. 2019-05-21 Uroš Bizjak PR target/90547 * config/i386/i386.md (anddi_1 to andsi_1_zext splitter): Avoid calling gen_lowpart with CONST operand. testsuite/ChangeLog: Backported from mainline 2019-05-21 Uroš Bizjak PR target/90547 * gcc.target/i386/pr90547.c: New test. From-SVN: r271537 --- gcc/ChangeLog | 15 +++++++++++++++ gcc/config/i386/cpuid.h | 17 +++++++++++++++++ gcc/config/i386/i386.md | 8 ++++++++ gcc/testsuite/ChangeLog | 8 ++++++++ gcc/testsuite/gcc.target/i386/pr90547.c | 21 +++++++++++++++++++++ 5 files changed, 69 insertions(+) create mode 100644 gcc/testsuite/gcc.target/i386/pr90547.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 59d39e55ebb0..785793af037c 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,18 @@ +2019-05-23 Uroš Bizjak + + Backported from mainline + 2019-05-21 Uroš Bizjak + + * config/i386/cpuid.h (__cpuid): For 32bit targets, zero + %ebx and %ecx bafore calling cpuid with leaf 1 or + non-constant leaf argument. + + 2019-05-21 Uroš Bizjak + + PR target/90547 + * config/i386/i386.md (anddi_1 to andsi_1_zext splitter): + Avoid calling gen_lowpart with CONST operand. + 2019-05-20 Kelvin Nilsen Backport from mainline. diff --git a/gcc/config/i386/cpuid.h b/gcc/config/i386/cpuid.h index b3b0f912c986..df90089a96fb 100644 --- a/gcc/config/i386/cpuid.h +++ b/gcc/config/i386/cpuid.h @@ -167,10 +167,27 @@ #define signature_VORTEX_ecx 0x436f5320 #define signature_VORTEX_edx 0x36387865 +#ifndef __x86_64__ +/* At least one cpu (Winchip 2) does not set %ebx and %ecx + for cpuid leaf 1. Forcibly zero the two registers before + calling cpuid as a precaution. */ +#define __cpuid(level, a, b, c, d) \ + do { \ + if (__builtin_constant_p (level) && (level) != 1) \ + __asm__ ("cpuid\n\t" \ + : "=a" (a), "=b" (b), "=c" (c), "=d" (d) \ + : "0" (level)); \ + else \ + __asm__ ("cpuid\n\t" \ + : "=a" (a), "=b" (b), "=c" (c), "=d" (d) \ + : "0" (level), "1" (0), "2" (0)); \ + } while (0) +#else #define __cpuid(level, a, b, c, d) \ __asm__ ("cpuid\n\t" \ : "=a" (a), "=b" (b), "=c" (c), "=d" (d) \ : "0" (level)) +#endif #define __cpuid_count(level, count, a, b, c, d) \ __asm__ ("cpuid\n\t" \ diff --git a/gcc/config/i386/i386.md b/gcc/config/i386/i386.md index b665dc5834a5..c36023f2c4d4 100644 --- a/gcc/config/i386/i386.md +++ b/gcc/config/i386/i386.md @@ -8275,6 +8275,14 @@ operands[2] = shallow_copy_rtx (operands[2]); PUT_MODE (operands[2], SImode); } + else if (GET_CODE (operands[2]) == CONST) + { + /* (const:DI (plus:DI (symbol_ref:DI ("...")) (const_int N))) */ + operands[2] = copy_rtx (operands[2]); + PUT_MODE (operands[2], SImode); + PUT_MODE (XEXP (operands[2], 0), SImode); + PUT_MODE (XEXP (XEXP (operands[2], 0), 0), SImode); + } else operands[2] = gen_lowpart (SImode, operands[2]); }) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 35da4a2b8bda..ba9467fae51e 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,11 @@ +2019-05-23 Uroš Bizjak + + Backported from mainline + 2019-05-21 Uroš Bizjak + + PR target/90547 + * gcc.target/i386/pr90547.c: New test. + 2019-05-20 Kelvin Nilsen Backport from mainline. diff --git a/gcc/testsuite/gcc.target/i386/pr90547.c b/gcc/testsuite/gcc.target/i386/pr90547.c new file mode 100644 index 000000000000..fcfe66953b02 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr90547.c @@ -0,0 +1,21 @@ +/* PR target/90547 */ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ + +void +foo () +{ + void *g[] = {&&a, &&b}; + + for (unsigned c = 0x1F;; c >>= 1) + { + unsigned d = (long)("a"+1); + long e = 8; + + while (e) + { + a: goto *g[c&d]; + b: e--; + } + } +} -- 2.47.2