Index: i386.md =================================================================== --- i386.md (revision 119532) +++ i386.md (working copy) @@ -18141,10 +18141,20 @@ ;; Block operation instructions +;; There is no need to emit cld in front of string operations, as x86 ABI +;; mandates that the direction flag is cleared on function entry and exit. +;; It is assumed that sane inline assembler code that sets direction flag +;; clears it at the end of assembler block as well. +;; Although empty, this insn pattern is kept in the machine description, +;; so if gcc ever emits "std" instruction, then "cld" has to be emitted +;; (probably via optimize mode switching) to clear direction flag in front +;; of string operation and to satisfy ABI requirements on function entry +;; and exit. + (define_insn "cld" [(set (reg:SI DIRFLAG_REG) (const_int 0))] "" - "cld" + "" [(set_attr "type" "cld")]) (define_expand "movmemsi"