From: Jakub Jelinek Date: Tue, 14 May 2013 08:55:34 +0000 (+0200) Subject: expmed.c (expand_shift_1): Canonicalize rotates by constant bitsize / 2 to bitsize... X-Git-Tag: releases/gcc-4.9.0~5911 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=75776c6d256cf2db9cd470484445bff01c7e30fa;p=thirdparty%2Fgcc.git expmed.c (expand_shift_1): Canonicalize rotates by constant bitsize / 2 to bitsize - 1. * expmed.c (expand_shift_1): Canonicalize rotates by constant bitsize / 2 to bitsize - 1. * simplify-rt.x (simplify_binary_operation_1) : Likewise. Revert: 2013-05-10 Jakub Jelinek * config/i386/i386.md (rotateinv): New code attr. (*3_1, *si3_1_zext, *qi3_1_slp): Emit rorl %eax instead of roll $31, %eax, etc. From-SVN: r198864 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index f225d8057658..a751b29d99fa 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,18 @@ +2013-05-14 Jakub Jelinek + + * expmed.c (expand_shift_1): Canonicalize rotates by + constant bitsize / 2 to bitsize - 1. + * simplify-rt.x (simplify_binary_operation_1) : Likewise. + + Revert: + 2013-05-10 Jakub Jelinek + + * config/i386/i386.md (rotateinv): New code attr. + (*3_1, *si3_1_zext, + *qi3_1_slp): Emit rorl %eax instead of + roll $31, %eax, etc. + 2013-05-14 Richard Biener PR middle-end/57235 diff --git a/gcc/config/i386/i386.md b/gcc/config/i386/i386.md index fe86fb9d3aa7..417d784aff21 100644 --- a/gcc/config/i386/i386.md +++ b/gcc/config/i386/i386.md @@ -762,9 +762,6 @@ ;; Base name for insn mnemonic. (define_code_attr rotate [(rotate "rol") (rotatert "ror")]) -;; Base name for insn mnemonic of rotation in the other direction. -(define_code_attr rotateinv [(rotate "ror") (rotatert "rol")]) - ;; Mapping of abs neg operators (define_code_iterator absneg [abs neg]) @@ -9755,15 +9752,11 @@ return "#"; default: - if (TARGET_SHIFT1 || optimize_function_for_size_p (cfun)) - { - if (operands[2] == const1_rtx) - return "{}\t%0"; - if (CONST_INT_P (operands[2]) - && INTVAL (operands[2]) == GET_MODE_BITSIZE (mode) - 1) - return "{}\t%0"; - } - return "{}\t{%2, %0|%0, %2}"; + if (operands[2] == const1_rtx + && (TARGET_SHIFT1 || optimize_function_for_size_p (cfun))) + return "{}\t%0"; + else + return "{}\t{%2, %0|%0, %2}"; } } [(set_attr "isa" "*,bmi2") @@ -9825,14 +9818,11 @@ return "#"; default: - if (TARGET_SHIFT1 || optimize_function_for_size_p (cfun)) - { - if (operands[2] == const1_rtx) - return "{l}\t%k0"; - if (CONST_INT_P (operands[2]) && INTVAL (operands[2]) == 31) - return "{l}\t%k0"; - } - return "{l}\t{%2, %k0|%k0, %2}"; + if (operands[2] == const1_rtx + && (TARGET_SHIFT1 || optimize_function_for_size_p (cfun))) + return "{l}\t%k0"; + else + return "{l}\t{%2, %k0|%k0, %2}"; } } [(set_attr "isa" "*,bmi2") @@ -9879,15 +9869,11 @@ (clobber (reg:CC FLAGS_REG))] "ix86_binary_operator_ok (, mode, operands)" { - if (TARGET_SHIFT1 || optimize_function_for_size_p (cfun)) - { - if (operands[2] == const1_rtx) - return "{}\t%0"; - if (CONST_INT_P (operands[2]) - && INTVAL (operands[2]) == GET_MODE_BITSIZE (mode) - 1) - return "{}\t%0"; - } - return "{}\t{%2, %0|%0, %2}"; + if (operands[2] == const1_rtx + && (TARGET_SHIFT1 || optimize_function_for_size_p (cfun))) + return "{}\t%0"; + else + return "{}\t{%2, %0|%0, %2}"; } [(set_attr "type" "rotate") (set (attr "length_immediate") @@ -9909,14 +9895,11 @@ || (operands[1] == const1_rtx && TARGET_SHIFT1))" { - if (TARGET_SHIFT1 || optimize_function_for_size_p (cfun)) - { - if (operands[2] == const1_rtx) - return "{b}\t%0"; - if (CONST_INT_P (operands[2]) && INTVAL (operands[2]) == 7) - return "{b}\t%0"; - } - return "{b}\t{%1, %0|%0, %1}"; + if (operands[1] == const1_rtx + && (TARGET_SHIFT1 || optimize_function_for_size_p (cfun))) + return "{b}\t%0"; + else + return "{b}\t{%1, %0|%0, %1}"; } [(set_attr "type" "rotate1") (set (attr "length_immediate") diff --git a/gcc/expmed.c b/gcc/expmed.c index 6e61e9a402eb..c85e68cf617a 100644 --- a/gcc/expmed.c +++ b/gcc/expmed.c @@ -2122,6 +2122,20 @@ expand_shift_1 (enum tree_code code, enum machine_mode mode, rtx shifted, op1 = SUBREG_REG (op1); } + /* Canonicalize rotates by constant amount. If op1 is bitsize / 2, + prefer left rotation, if op1 is from bitsize / 2 + 1 to + bitsize - 1, use other direction of rotate with 1 .. bitsize / 2 - 1 + amount instead. */ + if (rotate + && CONST_INT_P (op1) + && IN_RANGE (INTVAL (op1), GET_MODE_BITSIZE (mode) / 2 + left, + GET_MODE_BITSIZE (mode) - 1)) + { + op1 = GEN_INT (GET_MODE_BITSIZE (mode) - INTVAL (op1)); + left = !left; + code = left ? LROTATE_EXPR : RROTATE_EXPR; + } + if (op1 == const0_rtx) return shifted; diff --git a/gcc/simplify-rtx.c b/gcc/simplify-rtx.c index 791f91a34a87..865d37d49c31 100644 --- a/gcc/simplify-rtx.c +++ b/gcc/simplify-rtx.c @@ -3250,6 +3250,18 @@ simplify_binary_operation_1 (enum rtx_code code, enum machine_mode mode, case ROTATERT: case ROTATE: + /* Canonicalize rotates by constant amount. If op1 is bitsize / 2, + prefer left rotation, if op1 is from bitsize / 2 + 1 to + bitsize - 1, use other direction of rotate with 1 .. bitsize / 2 - 1 + amount instead. */ + if (CONST_INT_P (trueop1) + && IN_RANGE (INTVAL (trueop1), + GET_MODE_BITSIZE (mode) / 2 + (code == ROTATE), + GET_MODE_BITSIZE (mode) - 1)) + return simplify_gen_binary (code == ROTATE ? ROTATERT : ROTATE, + mode, op0, GEN_INT (GET_MODE_BITSIZE (mode) + - INTVAL (trueop1))); + /* FALLTHRU */ case ASHIFTRT: if (trueop1 == CONST0_RTX (mode)) return op0;