GCC 执行哪些 x86 32 位窥视孔?

What x86 32 bit peepholes does GCC perform?

我一直在浏览 GCC 源代码,但一直对如何提取这些代码感到困惑。任何人都可以提供有关如何提取这些窥视孔(程序集重写优化)的列表或信息吗?

GCC 代码:https://github.com/gcc-mirror/gcc

Edit:为了澄清,"peephole" 被定义为一个查找和替换模式,带有一些关联的附加条件以使重写有效(通常只是一些register/flags 活体信息)。

这里太笼统了,真的跑题了。

您可能会查看我的 documentation page of MELT; it has several useful references (notably the Indian GCC resource center),我写的大部分幻灯片都包含参考和教程 material...

大部分 GCC 优化发生在(目标和源中性)中间层,而不是后端。

peephole optimization这些天(准确地说)意义不大,GCC的大部分优化能力都不是来自它。

查看各种 *.md 文件并搜索 define_peephole

例如:gcc/config/i386/i386.md 包含(除其他外):

;; 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]);
})

相关文档在 GCC Internals Manual

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