Index: i386.md
===================================================================
--- i386.md	(revision 187223)
+++ i386.md	(working copy)
@@ -12114,18 +12114,22 @@
   ""
 {
   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 
+  else if (TARGET_GENERIC)
     /* tzcnt expands to rep;bsf and we can use it even if !TARGET_BMI.  */
     return "rep; bsf{<imodesuffix>}\t{%1, %0|%0, %1}";
+
+  return "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)")
+       (and (match_test "optimize_function_for_size_p (cfun)")
+	    (not (ior (match_test "TARGET_BMI")
+		      (match_test "TARGET_GENERIC"))))
        (const_string "0")
        (const_string "1")))
    (set_attr "mode" "<MODE>")])
@@ -12137,18 +12141,22 @@
   ""
 {
   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 
+  else if (TARGET_GENERIC)
     /* tzcnt expands to rep;bsf and we can use it even if !TARGET_BMI.  */
     return "rep; bsf{<imodesuffix>}\t{%1, %0|%0, %1}";
+
+  return "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)")
+       (and (match_test "optimize_function_for_size_p (cfun)")
+	    (not (ior (match_test "TARGET_BMI")
+		      (match_test "TARGET_GENERIC"))))
        (const_string "0")
        (const_string "1")))
    (set_attr "mode" "<MODE>")])
