This is an archive of the discontinued LLVM Phabricator instance.

[AArc64][SVE] Fold constant multiply of element count
ClosedPublic

Authored by c-rhodes on Dec 4 2019, 6:38 AM.

Details

Summary

E.g.

%0 = tail call i64 @llvm.aarch64.sve.cntw(i32 31)
%mul = mul i64 %0, <const>

Should emit:

cntw    x0, all, mul #<const>

For <const> in the range 1-16.

Patch by Kerry McLaughlin

Event Timeline

c-rhodes created this revision.Dec 4 2019, 6:38 AM
Herald added a project: Restricted Project. · View Herald TranscriptDec 4 2019, 6:38 AM
sdesmalen added inline comments.Dec 10 2019, 5:31 AM
llvm/lib/Target/AArch64/AArch64ISelDAGToDAG.cpp
167

nit: this is perhaps personal preference, but I always prefer code like this being in the form:

if (invalidating condition)
  return false;
if (invalidating condition2)
  return false;
  :
return true;
llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
9437

this is missing a default case.

c-rhodes updated this revision to Diff 233608.Dec 12 2019, 6:41 AM
  • Refactored SelectRDVLImm and SelectShiftImm into same function by adding a extra template argument for Shift.
  • Added default to switch in IsSVECntIntrinsic
c-rhodes marked 2 inline comments as done.Dec 12 2019, 6:44 AM
c-rhodes added inline comments.
llvm/lib/Target/AArch64/AArch64ISelDAGToDAG.cpp
167

Done for the check Scale is a factor of imm. I've left the low/high range checks as I think it's more readable as it is.

sdesmalen accepted this revision.Dec 17 2019, 1:40 AM

LGTM! Thanks @c-rhodes

llvm/lib/Target/AArch64/AArch64ISelDAGToDAG.cpp
162

nit: Low/High -> Min/Max ?

llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
9455

nit:

There's nothing to do if the immediate can be packed into an instruction

->

Allow the scaling to be folded into the `cnt` instruction by preventing
the scaling to be obscured here. That makes it easier to pattern match.
This revision is now accepted and ready to land.Dec 17 2019, 1:40 AM
This revision was automatically updated to reflect the committed changes.
c-rhodes marked an inline comment as done.