[all-commits] [llvm/llvm-project] 93ab99: [LoopIdiom] Recognize the ctlz/cttz idiom when the...
Konstantin Bogdanov via All-commits
all-commits at lists.llvm.org
Thu Sep 10 11:30:41 PDT 2026
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: 93ab99f40d86dead34ccb0d2aa45dfdd06d65cc9
https://github.com/llvm/llvm-project/commit/93ab99f40d86dead34ccb0d2aa45dfdd06d65cc9
Author: Konstantin Bogdanov <thevar1able at users.noreply.github.com>
Date: 2026-09-11 (Fri, 11 Sep 2026)
Changed paths:
M llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp
M llvm/test/Transforms/LoopIdiom/X86/ctlz.ll
M llvm/test/Transforms/PhaseOrdering/X86/ctlz-loop.ll
Log Message:
-----------
[LoopIdiom] Recognize the ctlz/cttz idiom when the input is known non-zero (#222373)
LoopIdiomRecognize converts a shift-until-zero loop to `ctlz`/`cttz`.
When the loop uses the count outside the loop, it needs a zero check of
the input before the loop. Without the check, the inputs 0 and 1 give
the same count. The recognizer stops when the check is not present.
The check is not necessary when the input is known non-zero. InstCombine
can remove the check for such inputs. Then the recognizer does not
convert the loop. This happens in `sbc_calc_scalefactors` from ffmpeg
with #222334: the input is an or reduction that starts at 32768, so it
is never zero, and the loop stays a loop.
This patch makes the recognizer accept a known non-zero input in place
of the zero check. The conversion is exact in this case.
`ctlz-loop.ll` in PhaseOrdering had a FIXME for a loop over `abs(n)`.
The recognizer now converts that loop too.
For the ffmpeg case, `isKnownNonZero` must also see that an or
recurrence with a non-zero start is non-zero. That change goes into
#222334.
To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications
More information about the All-commits
mailing list