[PATCH] D117210: [CodeGen] Support folds of not(cmp(cc, ...)) -> cmp(!cc, ...) for scalable vectors

Sander de Smalen via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 27 09:36:32 PST 2022


sdesmalen added inline comments.
Herald added a subscriber: pcwang-thead.


================
Comment at: llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp:3160
   APInt CVal;
   if (auto *CN = dyn_cast<ConstantSDNode>(N)) {
     CVal = CN->getAPIntValue();
----------------
david-arm wrote:
> sdesmalen wrote:
> > Instead of checking for SPLAT_VECTOR explicitly, how about:
> > 
> >   if (auto *CN = dyn_cast<ConstantSDNode>(N)) {
> >     CVal = CN->getAPIntValue();
> >   } else if (isConstantSplatVector(N, CVal)) {
> >     unsigned EltWidth = N->getValueType(0).getScalarSizeInBits();
> >     if (EltWidth < CVal.getBitwidth())
> >       CVal = CVal.trunc(EltWidth);
> >   } else
> >     return false;
> > 
> Sadly this doesn't work because `isConstantSplatVector` demands the element width of the result be the same as the element width in the BuildVectorSDNode, which means we end up with lots of failing tests. It's just a minor point, but `isConstantSplatVector` also permits FP splats, so we'd have to restrict it to integer too.
In that case, maybe you can use
  ConstantSDNode* llvm::isConstOrConstSplat(SDValue N, bool AllowUndefs, bool AllowTruncation)
which allows you to specify whether truncation is allowed?

It's bonkers how many of these functions exist...


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D117210/new/

https://reviews.llvm.org/D117210



More information about the llvm-commits mailing list