Created attachment 40278 [details] reproducer > g++ -O2 -march=nehalem -o opt illegal_inst.cpp illegal_inst_const.cpp > ./opt Illegal instruction This is regression, which was introduced in trunk couple days ago. > gcc --version gcc (GCC) 7.0.0 20161207 (experimental)
g++ -O2 -S illegal_inst.cpp -o - | c++filt foo(): .LFB12: .cfi_startproc ud2 .cfi_endproc
% cat illegal_inst.cpp extern signed char var_13; long int rrr; void foo() { rrr = !0 % ((var_13 < 0) << 21); }
Started with r243255: commit 458de25d72182951e17489052becf952f6b63592 Author: bonzini <bonzini@138bc75d-0d04-0410-961f-82ee72b054a4> Date: Mon Dec 5 13:19:34 2016 +0000 gcc: * match.pd: Simplify X ? C : 0 where C is a power of 2 and X tests a single bit.
From: void foo() () { signed char var_13.0_1; signed char _2; int _3; int _4; int _5; long int _6; <bb 2> [0.0%]: var_13.0_1 = var_13; _2 = var_13.0_1 >> -14; _3 = (int) _2; _4 = _3 & 2097152; _5 = 1 % _4; _6 = (long int) _5; rrr = _6; return; } To (ccp1): void foo() () { signed char var_13.0_1; int _5; long int _6; <bb 2> [0.0%]: var_13.0_1 = var_13; _5 = 1 % 0; _6 = (long int) _5; rrr = _6; return; }
Already the >> -14 looks wrong.
Created attachment 40284 [details] gcc7-pr78720.patch Untested fix.
Author: jakub Date: Sat Dec 10 12:06:12 2016 New Revision: 243516 URL: https://gcc.gnu.org/viewcvs?rev=243516&root=gcc&view=rev Log: PR tree-optimization/78720 * match.pd (A < 0 ? C : 0): Only optimize for signed A. If shift is negative, sign extend to @1's type and than AND with C. * gcc.c-torture/execute/pr78720.c: New test. Added: trunk/gcc/testsuite/gcc.c-torture/execute/pr78720.c Modified: trunk/gcc/ChangeLog trunk/gcc/match.pd trunk/gcc/testsuite/ChangeLog
Fixed.
*** Bug 78769 has been marked as a duplicate of this bug. ***