[PATCH] D144777: [InstCombine] Fold signbit test of a pow2 or zero
Simon Pilgrim via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sun Feb 26 04:00:25 PST 2023
RKSimon added a comment.
Please can you add vector test coverage?
================
Comment at: llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp:1343
+ // icmp sgt (and (sub 0, X), X), -1 --> icmp ne (X, CI)
+ if (match(Op0, m_OneUse(m_And(m_Sub(m_Zero(), m_Value(X)), m_Deferred(X))))) {
+ Constant *CI = ConstantInt::get(
----------------
junaire wrote:
> goldstein.w.n wrote:
> > goldstein.w.n wrote:
> > > goldstein.w.n wrote:
> > > > There are other power of 2 patterns. Maybe use `isKnownPowerOf2`?
> > > disregard, misunderstood the patch.
> > `m_Sub(m_Zero(), m_Value(X))` -> `m_Neg(m_Value(X))`?
> > Also do you need `m_OneUse`? This shouldn't ever create more instructions.
> > Also do you need m_OneUse? This shouldn't ever create more instructions.
>
> I thought it was unnecessary at first, but then it cause a regression in `smax_xor_pow2_neg`,
> so I added it.
>
> ```
> @@ -137,7 +137,10 @@ define i8 @smax_xor_pow2_neg(i8 %x, i8 %y) { ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[Y:%.*]], -128 ; CHECK-NEXT: br i1 [[CMP]], label [[NEG:%.*]], label [[POS:%.*]] ; CHECK: neg: -; CHECK-NEXT: [[R:%.*]] = and i8 [[X:%.*]], 127 +; CHECK-NEXT: [[NY:%.*]] = sub i8 0, [[Y]] +; CHECK-NEXT: [[YP2:%.*]] = and i8 [[NY]], [[Y]] +; CHECK-NEXT: [[X_XOR:%.*]] = xor i8 [[YP2]], [[X:%.*]] +; CHECK-NEXT: [[R:%.*]] = call i8 @llvm.smax.i8(i8 [[X]], i8 [[X_XOR]]) ; CHECK-NEXT: ret i8 [[R]] ; CHECK: pos: ; CHECK-NEXT: call void @barrier()
> ```
Use m_c_And (and add suitable test coverage)?
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D144777/new/
https://reviews.llvm.org/D144777
More information about the llvm-commits
mailing list