i386.md (ctz<mode>2): Emit rep;bsf even for !TARGET_BMI.
authorUros Bizjak <ubizjak@gmail.com>
Sun, 6 May 2012 23:07:38 +0000 (01:07 +0200)
committerUros Bizjak <uros@gcc.gnu.org>
Sun, 6 May 2012 23:07:38 +0000 (01:07 +0200)
* config/i386/i386.md (ctz<mode>2): Emit rep;bsf even for !TARGET_BMI.
Emit bsf when optimizing for size.
(*ffs<mode>_1): Ditto.

Co-Authored-By: Paolo Bonzini <bonzini@gnu.org>
From-SVN: r187219

gcc/ChangeLog
gcc/config/i386/i386.md

index aa909e352087a7d41fdfb9e33bc312e2aef3427a..bba151a7f775c271b826fd9a699a018b8a15f336 100644 (file)
@@ -1,3 +1,10 @@
+2012-05-07  Uros Bizjak  <ubizjak@gmail.com>
+           Paolo Bonzini  <bonzini@gnu.org>
+
+       * config/i386/i386.md (ctz<mode>2): Emit rep;bsf even for !TARGET_BMI.
+       Emit bsf when optimizing for size.
+       (*ffs<mode>_1): Ditto.
+
 2012-05-07  Oleg Endo  <olegendo@gcc.gnu.org>
 
        PR target/53250
index 360bd32b9abd3f38985b4218cf45c9d5ebd776a9..b78054fd5498ed54ad3801321b978ccf07da27c5 100644 (file)
    (set (match_operand:SWI48 0 "register_operand" "=r")
        (ctz:SWI48 (match_dup 1)))]
   ""
-  "bsf{<imodesuffix>}\t{%1, %0|%0, %1}"
+{
+  if (optimize_function_for_size_p (cfun))
+    return "bsf{<imodesuffix>}\t{%1, %0|%0, %1}";
+  else if (TARGET_BMI)
+    return "tzcnt{<imodesuffix>}\t{%1, %0|%0, %1}";
+  else 
+    /* tzcnt expands to rep;bsf and we can use it even if !TARGET_BMI.  */
+    return "rep; bsf{<imodesuffix>}\t{%1, %0|%0, %1}";
+}
   [(set_attr "type" "alu1")
    (set_attr "prefix_0f" "1")
+   (set (attr "prefix_rep")
+     (if_then_else
+       (match_test "optimize_function_for_size_p (cfun)")
+       (const_string "0")
+       (const_string "1")))
    (set_attr "mode" "<MODE>")])
 
 (define_insn "ctz<mode>2"
    (clobber (reg:CC FLAGS_REG))]
   ""
 {
-  if (TARGET_BMI)
-    return "tzcnt{<imodesuffix>}\t{%1, %0|%0, %1}";
-  else
+  if (optimize_function_for_size_p (cfun))
     return "bsf{<imodesuffix>}\t{%1, %0|%0, %1}";
+  else if (TARGET_BMI)
+    return "tzcnt{<imodesuffix>}\t{%1, %0|%0, %1}";
+  else 
+    /* tzcnt expands to rep;bsf and we can use it even if !TARGET_BMI.  */
+    return "rep; bsf{<imodesuffix>}\t{%1, %0|%0, %1}";
 }
   [(set_attr "type" "alu1")
    (set_attr "prefix_0f" "1")
-   (set (attr "prefix_rep") (symbol_ref "TARGET_BMI"))
+   (set (attr "prefix_rep")
+     (if_then_else
+       (match_test "optimize_function_for_size_p (cfun)")
+       (const_string "0")
+       (const_string "1")))
    (set_attr "mode" "<MODE>")])
 
 (define_expand "clz<mode>2"