Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2368,6 +2368,7 @@ static std::optional<Instruction *> instCombineSVEUzp1(InstCombiner &IC,

// uzp1(to_svbool(A), to_svbool(B)) --> <A, B>
// uzp1(from_svbool(to_svbool(A)), from_svbool(to_svbool(B))) --> <A, B>

if ((match(II.getArgOperand(0),
m_Intrinsic<FromSVB>(m_Intrinsic<ToSVB>(m_Value(A)))) &&
match(II.getArgOperand(1),
Expand Down Expand Up @@ -2674,6 +2675,52 @@ static std::optional<Instruction *> instCombinePTrue(InstCombiner &IC,
return std::nullopt;
}

static std::optional<Instruction *> instCombineSVERev(InstCombiner &IC,
IntrinsicInst &II) {
// rev(rev(x)) -> x
switch (II.getIntrinsicID()) {
default:
return std::nullopt;

case Intrinsic::aarch64_sve_rev:
case Intrinsic::aarch64_sve_rev_b16:
case Intrinsic::aarch64_sve_rev_b32:
case Intrinsic::aarch64_sve_rev_b64: {
Value *InnerArg = II.getArgOperand(0);
IntrinsicInst *InnerRev = dyn_cast<IntrinsicInst>(InnerArg);
// Fold rev(rev(x)) -> x, if intrinsic IDs match and InnerRev has one use
if (InnerRev && InnerRev->getIntrinsicID() == II.getIntrinsicID() &&
InnerRev->hasOneUse())
return IC.replaceInstUsesWith(II, InnerRev->getArgOperand(0));

return std::nullopt;
}

case Intrinsic::aarch64_sve_revb:
case Intrinsic::aarch64_sve_revd:
case Intrinsic::aarch64_sve_revh:
case Intrinsic::aarch64_sve_revw: {
Value *InnerArg = II.getArgOperand(2);
IntrinsicInst *InnerRev = dyn_cast<IntrinsicInst>(InnerArg);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is still missing checks for the governing predicate.


// Early exit if InnerRev != outerId and doesn't only have one use
if (!InnerRev || InnerRev->getIntrinsicID() != II.getIntrinsicID() ||
!InnerRev->hasOneUse())
return std::nullopt;

Value *OuterPred = II.getArgOperand(0);
Value *OuterPassThru = II.getArgOperand(1);
Value *InnerPred = InnerRev->getArgOperand(0);
Value *InnerPassThru = InnerRev->getArgOperand(1);
Comment on lines +2711 to +2714
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These variables are all unused.


// Fold rev(rev(x)) -> x, if predicates and pass-thrus match
return IC.replaceInstUsesWith(II, InnerRev->getArgOperand(2));

return std::nullopt;
Comment on lines +2717 to +2719
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a return after a return?

}
}
}

std::optional<Instruction *>
AArch64TTIImpl::instCombineIntrinsic(InstCombiner &IC,
IntrinsicInst &II) const {
Expand Down Expand Up @@ -2773,6 +2820,15 @@ AArch64TTIImpl::instCombineIntrinsic(InstCombiner &IC,
return instCombineSVEInsr(IC, II);
case Intrinsic::aarch64_sve_ptrue:
return instCombinePTrue(IC, II);
case Intrinsic::aarch64_sve_rev:
case Intrinsic::aarch64_sve_rev_b16:
case Intrinsic::aarch64_sve_rev_b32:
case Intrinsic::aarch64_sve_rev_b64:
case Intrinsic::aarch64_sve_revb:
case Intrinsic::aarch64_sve_revd:
case Intrinsic::aarch64_sve_revh:
case Intrinsic::aarch64_sve_revw:
return instCombineSVERev(IC, II);
}

return std::nullopt;
Expand Down
Loading
Loading