From f259abd260739aca06f8760dcbc0a1a567018ff2 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Wed, 21 Nov 2018 11:45:58 +0100 Subject: [PATCH] re PR rtl-optimization/87817 (gcc.target/i386/bmi2-bzhi-2.c execution test) PR rtl-optimization/87817 * config/i386/i386.md (bmi2_bzhi_3, *bmi2_bzhi_3, *bmi2_bzhi_3_1, *bmi2_bzhi_3_1_ccz): Use IF_THEN_ELSE in the pattern to avoid triggering UB when operands[2] is zero. (tbm_bextri_): New expander. Renamed the old define_insn to ... (*tbm_bextri_): ... this. From-SVN: r266340 --- gcc/ChangeLog | 9 +++++ gcc/config/i386/i386.md | 77 +++++++++++++++++++++++++++++------------ 2 files changed, 63 insertions(+), 23 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index bff4dfb5daa..005ce0f49d9 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,12 @@ +2018-11-21 Jakub Jelinek + + PR rtl-optimization/87817 + * config/i386/i386.md (bmi2_bzhi_3, *bmi2_bzhi_3, + *bmi2_bzhi_3_1, *bmi2_bzhi_3_1_ccz): Use IF_THEN_ELSE + in the pattern to avoid triggering UB when operands[2] is zero. + (tbm_bextri_): New expander. Renamed the old define_insn to ... + (*tbm_bextri_): ... this. + 2018-11-21 Tom de Vries PR driver/79855 diff --git a/gcc/config/i386/i386.md b/gcc/config/i386/i386.md index 1a3a1791274..2231204b29c 100644 --- a/gcc/config/i386/i386.md +++ b/gcc/config/i386/i386.md @@ -13615,12 +13615,15 @@ (define_expand "bmi2_bzhi_3" [(parallel [(set (match_operand:SWI48 0 "register_operand") - (zero_extract:SWI48 - (match_operand:SWI48 1 "nonimmediate_operand") - (umin:SWI48 - (and:SWI48 (match_operand:SWI48 2 "register_operand") - (const_int 255)) - (match_dup 3)) + (if_then_else:SWI48 + (ne:QI (and:SWI48 (match_operand:SWI48 2 "register_operand") + (const_int 255)) + (const_int 0)) + (zero_extract:SWI48 + (match_operand:SWI48 1 "nonimmediate_operand") + (umin:SWI48 (and:SWI48 (match_dup 2) (const_int 255)) + (match_dup 3)) + (const_int 0)) (const_int 0))) (clobber (reg:CC FLAGS_REG))])] "TARGET_BMI2" @@ -13628,12 +13631,15 @@ (define_insn "*bmi2_bzhi_3" [(set (match_operand:SWI48 0 "register_operand" "=r") - (zero_extract:SWI48 - (match_operand:SWI48 1 "nonimmediate_operand" "rm") - (umin:SWI48 - (and:SWI48 (match_operand:SWI48 2 "register_operand" "r") - (const_int 255)) - (match_operand:SWI48 3 "const_int_operand" "n")) + (if_then_else:SWI48 + (ne:QI (and:SWI48 (match_operand:SWI48 2 "register_operand" "r") + (const_int 255)) + (const_int 0)) + (zero_extract:SWI48 + (match_operand:SWI48 1 "nonimmediate_operand" "rm") + (umin:SWI48 (and:SWI48 (match_dup 2) (const_int 255)) + (match_operand:SWI48 3 "const_int_operand" "n")) + (const_int 0)) (const_int 0))) (clobber (reg:CC FLAGS_REG))] "TARGET_BMI2 && INTVAL (operands[3]) == * BITS_PER_UNIT" @@ -13644,11 +13650,13 @@ (define_insn "*bmi2_bzhi_3_1" [(set (match_operand:SWI48 0 "register_operand" "=r") - (zero_extract:SWI48 - (match_operand:SWI48 1 "nonimmediate_operand" "rm") - (umin:SWI48 - (zero_extend:SWI48 (match_operand:QI 2 "register_operand" "r")) - (match_operand:SWI48 3 "const_int_operand" "n")) + (if_then_else:SWI48 + (ne:QI (match_operand:QI 2 "register_operand" "r") (const_int 0)) + (zero_extract:SWI48 + (match_operand:SWI48 1 "nonimmediate_operand" "rm") + (umin:SWI48 (zero_extend:SWI48 (match_dup 2)) + (match_operand:SWI48 3 "const_int_operand" "n")) + (const_int 0)) (const_int 0))) (clobber (reg:CC FLAGS_REG))] "TARGET_BMI2 && INTVAL (operands[3]) == * BITS_PER_UNIT" @@ -13660,11 +13668,13 @@ (define_insn "*bmi2_bzhi_3_1_ccz" [(set (reg:CCZ FLAGS_REG) (compare:CCZ - (zero_extract:SWI48 - (match_operand:SWI48 1 "nonimmediate_operand" "rm") - (umin:SWI48 - (zero_extend:SWI48 (match_operand:QI 2 "register_operand" "r")) - (match_operand:SWI48 3 "const_int_operand" "n")) + (if_then_else:SWI48 + (ne:QI (match_operand:QI 2 "register_operand" "r") (const_int 0)) + (zero_extract:SWI48 + (match_operand:SWI48 1 "nonimmediate_operand" "rm") + (umin:SWI48 (zero_extend:SWI48 (match_dup 2)) + (match_operand:SWI48 3 "const_int_operand" "n")) + (const_int 0)) (const_int 0)) (const_int 0))) (clobber (match_scratch:SWI48 0 "=r"))] @@ -13697,7 +13707,28 @@ (set_attr "mode" "")]) ;; TBM instructions. -(define_insn "tbm_bextri_" +(define_expand "tbm_bextri_" + [(parallel + [(set (match_operand:SWI48 0 "register_operand") + (zero_extract:SWI48 + (match_operand:SWI48 1 "nonimmediate_operand") + (match_operand 2 "const_0_to_255_operand" "N") + (match_operand 3 "const_0_to_255_operand" "N"))) + (clobber (reg:CC FLAGS_REG))])] + "TARGET_TBM" +{ + if (operands[2] == const0_rtx + || INTVAL (operands[3]) >= * BITS_PER_UNIT) + { + emit_move_insn (operands[0], const0_rtx); + DONE; + } + if (INTVAL (operands[2]) + INTVAL (operands[3]) + > * BITS_PER_UNIT) + operands[2] = GEN_INT ( * BITS_PER_UNIT - INTVAL (operands[3])); +}) + +(define_insn "*tbm_bextri_" [(set (match_operand:SWI48 0 "register_operand" "=r") (zero_extract:SWI48 (match_operand:SWI48 1 "nonimmediate_operand" "rm") -- 2.30.2