[PATCH] D130248: [LoongArch] Offset folding for frameindex

Ray Wang via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 25 05:37:40 PDT 2022


wangleiat added a comment.

In D130248#3674149 <https://reviews.llvm.org/D130248#3674149>, @barannikov88 wrote:

> In D130248#3674127 <https://reviews.llvm.org/D130248#3674127>, @MaskRay wrote:
>
>> Do you know why csky/hexagon need `isOrEquivalentToAdd` while other targets can produce efficient code without `isOrEquivalentToAdd` ?
>
> Other targets just do that manually in *ISelDAGToDAG.cpp file. E.g. X86:
>
>   case ISD::OR:
>     // We want to look through a transform in InstCombine and DAGCombiner that
>     // turns 'add' into 'or', so we can treat this 'or' exactly like an 'add'.
>     // Example: (or (and x, 1), (shl y, 3)) --> (add (and x, 1), (shl y, 3))
>     // An 'lea' can then be used to match the shift (multiply) and add:
>     // and $1, %esi
>     // lea (%rsi, %rdi, 8), %rax
>     if (CurDAG->haveNoCommonBitsSet(N.getOperand(0), N.getOperand(1)) &&
>         !matchAdd(N, AM, Depth))
>       return false;
>     break;
>
> ARM:
>
>   // Determine whether an ISD::OR's operands are suitable to turn the operation
>   // into an addition, which often has more compact encodings.
>   bool ARMDAGToDAGISel::SelectAddLikeOr(SDNode *Parent, SDValue N, SDValue &Out) {
>     assert(Parent->getOpcode() == ISD::OR && "unexpected parent");
>     Out = N;
>     return CurDAG->haveNoCommonBitsSet(N, Parent->getOperand(1));
>   }

Agree, The `DAGCombiner` will almost certainly be generated `ISD::OR` operator for frameindex. (natural alignment attribute?)



================
Comment at: llvm/lib/Target/LoongArch/LoongArchInstrInfo.td:591
+/// Predicates
+def IsOrAdd: PatFrag<(ops node:$A, node:$B), (or node:$A, node:$B), [{
+    return isOrEquivalentToAdd(N);
----------------
barannikov88 wrote:
> You can check for both ADD and OR in one PatFrags, e.g.:
> ```
> def add_like : PatFrags<(ops node:$lhs, node:$rhs),
>                         [(add $lhs, $rhs), (or $lhs, $rhs)], [{
>   return N->getOpcode() == ISD::ADD || isOrEquivalentToAdd(N);
> }]>;
> ```
> This will halve the number of patterns. Up to you, of course.
> You can check for both ADD and OR in one PatFrags, e.g.:
> ```
> def add_like : PatFrags<(ops node:$lhs, node:$rhs),
>                         [(add $lhs, $rhs), (or $lhs, $rhs)], [{
>   return N->getOpcode() == ISD::ADD || isOrEquivalentToAdd(N);
> }]>;
> ```
> This will halve the number of patterns. Up to you, of course.

Thanks, I will do that.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130248



More information about the llvm-commits mailing list