What x86 32 bit peepholes does GCC perform?

廉价感情. 提交于 2019-12-24 13:35:02

问题


I've been browsing through the GCC source code and I've been stumped on how to extract these. Can anyone provide a list or information on how to extract these peepholes (assembly rewrite optimizations)?

GCC code: https://github.com/gcc-mirror/gcc

Edit: To clarify, a "peephole" is defined to be a find and replace pattern with some associated side conditions for the rewrite to be valid (often just some register/flags liveness information).


回答1:


Look in the various *.md files and search for define_peephole.

For example: gcc/config/i386/i386.md contains (among many others):

;; For HI, SI and DI modes, or $-1,reg is smaller than mov $-1,reg.
(define_peephole2
  [(set (match_operand:SWI248 0 "register_operand")
    (const_int -1))]
  "(optimize_insn_for_size_p () || TARGET_MOVE_M1_VIA_OR)
   && GENERAL_REGNO_P (REGNO (operands[0]))
   && peep2_regno_dead_p (0, FLAGS_REG)"
  [(parallel [(set (match_dup 0) (const_int -1))
          (clobber (reg:CC FLAGS_REG))])]
{
  if (<MODE_SIZE> < GET_MODE_SIZE (SImode))
    operands[0] = gen_lowpart (SImode, operands[0]);
})

The relevant documentation is in the GCC Internals Manual

https://gcc.gnu.org/onlinedocs/gccint/Peephole-Definitions.html#Peephole-Definitions




回答2:


It is really off-topic since too broad here.

You might look into my documentation page of MELT; it has several useful references (notably the Indian GCC resource center), and most of the slides I wrote contain reference and tutorial material...

Most of GCC optimizations happen in the (target & source neutral) middle-end layers, not in the backend.

And peephole optimization does not means much (precisely) these days, and most of the optimization power of GCC does not come from it.



来源:https://stackoverflow.com/questions/33286725/what-x86-32-bit-peepholes-does-gcc-perform

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!