[PATCH] D112268: [LegalizeTypes][RISCV][PowerPC] Expand CTLZ/CTTZ/CTPOP instead of promoting if they'll be expanded later.
Craig Topper via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Nov 17 12:17:59 PST 2021
craig.topper added a comment.
In D112268#3137708 <https://reviews.llvm.org/D112268#3137708>, @thopre wrote:
> Hi @craig.topper ,
>
> This caused a regression for us for i16 cttz with is_undef_zero true because cttz is expanded to a sequence using ctpop which loses the fact that any output is ok for the 0 case.
>
> t17: i16 = sub t9, Constant:i16<1>
> t19: i16 = xor t9, Constant:i16<-1>
> t20: i16 = and t19, t17
> t21: i16 = ctpop t20
>
> So when this gets promoted, a mask is inserted to not have the result of ctpop change when `t9` is 0.
>
> t15: i32 = extract_vector_elt t2, Constant:i32<0>
> t25: i32 = xor t15, Constant:i32<-1>
> t23: i32 = sub t15, Constant:i32<1>
> t26: i32 = and t25, t23
> t28: i32 = and t26, Constant:i32<65535>
> t29: i32 = ctpop t28
>
> Prior to this patch, we'd get:
>
> t19: i32 = sub t15, Constant:i32<1>
> t21: i32 = xor t15, Constant:i32<-1>
> t22: i32 = and t21, t19
> t23: i32 = ctpop t22
>
> I thought about inserting some llvm.assume saying the value is non zero when expanding but those work at IR level. Any pointer on how to solve this? Best regards.
I take it i32 ctpop is legal for your target or the i16 ctpop would have gotten expanded too?
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D112268/new/
https://reviews.llvm.org/D112268
More information about the llvm-commits
mailing list