> On 10 Jul 2026, at 04:05, Jeffrey Law <[email protected]> wrote:
> 
> 
> 
> On 7/6/2026 8:14 AM, [email protected] wrote:
>> From: Kyrylo Tkachov <[email protected]>
>> 
>> A double-word count of trailing or leading zeros written as
>> 
>>   lo ? ctz (lo) : 32 + ctz (hi)
>> 
>> with lo and hi the low and high halves of X equals a single wide ctzll (X),
>> and likewise for clz, but GCC kept the branch and two narrow counts.
>> Recognize the idiom in phiopt diamond handling and emit one .CTZ/.CLZ on the
>> double-word value.  As __builtin_c[lt]z is undefined at zero, so is the
>> result, so a one-argument .CTZ/.CLZ is used.
>> 
>> Based on a prototype by Andrea, refactored into helpers and extended
>> to handle clz as well as ctz, with testcases added.
>> 
>> Bootstrapped and tested on aarch64-none-linux-gnu and x86_64-linux.
>> 
>> PR tree-optimization/126035
>> 
>> gcc/ChangeLog:
>> 
>> * tree-ssa-phiopt.cc (clzctz_match_arm): New function.
>> (clzctz_decode_half): New function.
>> (clzctz_combine_replacement): New function.
>> (pass_phiopt::execute): Call it for the diamond case.
>> 
>> gcc/testsuite/ChangeLog:
>> 
>> * gcc.target/aarch64/pr126035.c: New test.
>> * gcc.target/aarch64/pr126035-clz.c: New test.
>> * gcc.target/aarch64/pr126035-run.c: New test.
>> * gcc.target/aarch64/pr126035-debug.c: New test.
>> * gcc.target/aarch64/pr126035-extra-pred.c: New test.
>> * gcc.target/aarch64/pr126035-narrow.c: New test.
>> 
>> Co-authored-by: Andrew Pinski <[email protected]>
>> Signed-off-by: Andrew Pinski <[email protected]>
>> Signed-off-by: Kyrylo Tkachov <[email protected]>
> So do we need review on this, or are you and Andrea iterating on a newer 
> version?  (Andrea mentioned this problem in another context)?

I sent this version before Andrea came up with the generalization, I think to 
extend phiopt to support middle bbs with >1 statement. I think that will 
supersede this first patch. From my side I’m waiting for that to land and then 
I’ll revisit this to see what can be dropped from these two patches. What I’m 
really after is patch 2/2 that tackles what’s actually in zstd from SPEC, but 
that may get simplified once Andrea’s improvement goes in.

Thanks,
Kyrill

> 
> jeff


Reply via email to