]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
doc: Document order of define_peephole2 scanning
authorHans-Peter Nilsson <hp@axis.com>
Tue, 18 Apr 2023 17:37:21 +0000 (19:37 +0200)
committerHans-Peter Nilsson <hp@bitrange.com>
Fri, 5 May 2023 23:10:37 +0000 (01:10 +0200)
I was a bit surprised when my newly-added define_peephole2 didn't
match, but it was because it was expected to partially match the
generated output of a previous define_peephole2, which matched and
modified the last insn of a sequence to be matched.  I had assumed
that the algorithm backed-up the size of the match-buffer, thereby
exposing newly created opportunities *with sufficient context* to all
define_peephole2's.  While things can change in that direction, let's
start with documenting the current state.

* doc/md.texi (define_peephole2): Document order of scanning.

gcc/doc/md.texi

index cc4a93a87638d442e3d96d3d6758adcb07b7e1be..37e537733c94347a4c9ae3cb8ad4afa94e1a66fc 100644 (file)
@@ -9371,6 +9371,15 @@ If the preparation falls through (invokes neither @code{DONE} nor
 @code{FAIL}), then the @code{define_peephole2} uses the replacement
 template.
 
+Insns are scanned in forward order from beginning to end for each basic
+block.  Matches are attempted in order of @code{define_peephole2}
+appearance in the @file{md} file.  After a successful replacement,
+scanning for further opportunities for @code{define_peephole2}, resumes
+with the first generated replacement insn as the first insn to be
+matched against all @code{define_peephole2}.  For the example above,
+after its successful replacement, the first insn that can be matched by
+a @code{define_peephole2} is @code{(set (match_dup 4) (match_dup 1))}.
+
 @end ifset
 @ifset INTERNALS
 @node Insn Attributes