From a42de35f0d1072fd695244913e354e1a670e9097 Mon Sep 17 00:00:00 2001 From: Uros Bizjak Date: Tue, 5 May 2015 06:36:19 +0200 Subject: [PATCH] re PR target/65871 (bzhi builtin/intrinsic wrongly assumes bzhi instruction doesn't set the ZF flag) PR target/65871 * config/i386/i386.md (*bmi_andn__ccno): New pattern. testsuite/ChangeLog: PR target/65871 * gcc.target/i386/pr65871-3.c: New test. From-SVN: r222795 --- gcc/ChangeLog | 11 +++++--- gcc/config/i386/i386.md | 31 ++++++++++++++++------- gcc/testsuite/ChangeLog | 9 +++++-- gcc/testsuite/gcc.target/i386/pr65871-3.c | 20 +++++++++++++++ 4 files changed, 57 insertions(+), 14 deletions(-) create mode 100644 gcc/testsuite/gcc.target/i386/pr65871-3.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 2ee441424f3..a9920d7c356 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,4 +1,9 @@ -2015-05-02 Jan Hubicka +2015-05-05 Uros Bizjak + + PR target/65871 + * config/i386/i386.md (*bmi_andn__ccno): New pattern. + +2015-05-04 Jan Hubicka * tree.c (verify_type): Check various uses of TYPE_MAXVAL; fix overactive TYPE_MIN_VALUE check and add FIXME for type @@ -438,8 +443,8 @@ 2015-04-29 Uros Bizjak PR target/65871 - * config/i386/i386.md (*bmi_bextr__cczonly): New pattern. - (*bmi2_bzhi_3_1_cczonly): Ditto. + * config/i386/i386.md (*bmi_bextr__ccz): New pattern. + (*bmi2_bzhi_3_1_ccz): Ditto. (setcc+movzbl peephole2): Check also clobbered reg. (setcc+andl peephole2): Ditto. diff --git a/gcc/config/i386/i386.md b/gcc/config/i386/i386.md index 8b0830c7a1b..3ce8f411c0a 100644 --- a/gcc/config/i386/i386.md +++ b/gcc/config/i386/i386.md @@ -12554,10 +12554,9 @@ ;; BMI instructions. (define_insn "*bmi_andn_" [(set (match_operand:SWI48 0 "register_operand" "=r,r") - (and:SWI48 - (not:SWI48 - (match_operand:SWI48 1 "register_operand" "r,r")) - (match_operand:SWI48 2 "nonimmediate_operand" "r,m"))) + (and:SWI48 + (not:SWI48 (match_operand:SWI48 1 "register_operand" "r,r")) + (match_operand:SWI48 2 "nonimmediate_operand" "r,m"))) (clobber (reg:CC FLAGS_REG))] "TARGET_BMI" "andn\t{%2, %1, %0|%0, %1, %2}" @@ -12565,11 +12564,25 @@ (set_attr "btver2_decode" "direct, double") (set_attr "mode" "")]) +(define_insn "*bmi_andn__ccno" + [(set (reg FLAGS_REG) + (compare + (and:SWI48 + (not:SWI48 (match_operand:SWI48 1 "register_operand" "r,r")) + (match_operand:SWI48 2 "nonimmediate_operand" "r,m")) + (const_int 0))) + (clobber (match_scratch:SWI48 0 "=r,r"))] + "TARGET_BMI && ix86_match_ccmode (insn, CCNOmode)" + "andn\t{%2, %1, %0|%0, %1, %2}" + [(set_attr "type" "bitmanip") + (set_attr "btver2_decode" "direct, double") + (set_attr "mode" "")]) + (define_insn "bmi_bextr_" [(set (match_operand:SWI48 0 "register_operand" "=r,r") - (unspec:SWI48 [(match_operand:SWI48 1 "nonimmediate_operand" "r,m") - (match_operand:SWI48 2 "register_operand" "r,r")] - UNSPEC_BEXTR)) + (unspec:SWI48 [(match_operand:SWI48 1 "nonimmediate_operand" "r,m") + (match_operand:SWI48 2 "register_operand" "r,r")] + UNSPEC_BEXTR)) (clobber (reg:CC FLAGS_REG))] "TARGET_BMI" "bextr\t{%2, %1, %0|%0, %1, %2}" @@ -12577,7 +12590,7 @@ (set_attr "btver2_decode" "direct, double") (set_attr "mode" "")]) -(define_insn "*bmi_bextr__cczonly" +(define_insn "*bmi_bextr__ccz" [(set (reg:CCZ FLAGS_REG) (compare:CCZ (unspec:SWI48 [(match_operand:SWI48 1 "nonimmediate_operand" "r,m") @@ -12680,7 +12693,7 @@ (set_attr "prefix" "vex") (set_attr "mode" "")]) -(define_insn "*bmi2_bzhi_3_1_cczonly" +(define_insn "*bmi2_bzhi_3_1_ccz" [(set (reg:CCZ FLAGS_REG) (compare:CCZ (zero_extract:SWI48 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 94ee3120469..37cdbf965d0 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2015-05-05 Uros Bizjak + + PR target/65871 + * gcc.target/i386/pr65871-3.c: New test. + 2015-05-04 Jeff Law Revert: @@ -174,7 +179,7 @@ scan pattern. * gfortran.dg/bound_9.f90: New test case. -2015-04-29 Uros Bizjak +2015-04-30 Uros Bizjak * g++.dg/ipa/devirt-28a.C: Require LTO effective target. * g++.dg/ext/sync-4.C (dg-additional-options): Use -march=pentium @@ -232,7 +237,7 @@ 2015-04-29 Uros Bizjak PR target/65871 - * gcc.target/i386/pr65871-1.c: New test + * gcc.target/i386/pr65871-1.c: New test. * gcc.target/i386/pr65871-2.c: Ditto. 2015-04-29 Marek Polacek diff --git a/gcc/testsuite/gcc.target/i386/pr65871-3.c b/gcc/testsuite/gcc.target/i386/pr65871-3.c new file mode 100644 index 00000000000..c7d9bdd96f5 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr65871-3.c @@ -0,0 +1,20 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -mbmi" } */ + +int foo (int x, int y) +{ + if (~x & y) + return 1; + + return 0; +} + +int bar (int x, int y) +{ + if ((~x & y) > 0) + return 1; + + return 0; +} + +/* { dg-final { scan-assembler-not "test" } } */ -- 2.30.2