[PATCH] D125988: [x86][SelectionDAG] Unroll vectorized FREM instructions which will be lowered to libcalls

Nabeel Omer via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu May 19 09:33:48 PDT 2022


n-omer created this revision.
n-omer added reviewers: RKSimon, andreadb, craig.topper.
Herald added subscribers: StephenFan, ecnelises, pengfei, hiraditya.
Herald added a project: All.
n-omer requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Currently, two element vectors produced as the result of a binary op are
widened to four element vectors on x86 by
`DAGTypeLegalizer::WidenVecRes_BinaryCanTrap`. If the op still isn't legal
after widening it is unrolled into scalar 4 scalar ops in selectionDAG before
being converted into a libcall. This way we end up with 4 libcalls (two of them
on known undef elements) instead of the original two libcalls.

This patch modifies `DAGTypeLegalizer::WidenVecRes_BinaryCanTrap` to ensure
that if it is known that an binary op will be turned into a libcall, it is
unrolled instead of being widened. This prevents the creation of the extra
scalar instructions on known undef elements and (eventually) libcalls with
known undef parameters which would otherwise be created when the op gets
expanded post widening. The patch also changes the `LegalizeAction` for
`ISD::FREM` to be `LibCall` on x86. This is not new, `ISD::FREM` is always
lowered to a `LibCall`, we've simply made it explicit. It also introduces basic
test coverage for ISD::FREM on x86.

llvm/test/CodeGen/X86/frem.ll:

  Introduces basic test coverage for `frem` on x86.

llvm/test/CodeGen/X86/frem-libcall.ll:

  Regression test for the change.

llvm/test/Analysis/CostModel/X86/arith-fp.ll:

  Test needed to be updated due to the cost model changing.

llvm/lib/Target/X86/X86ISelLowering.cpp:

  Treat `ISD::FREM` as a libcall on x86.

llvm/lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp:

  The change in SelectionDAG as mentioned above.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D125988

Files:
  llvm/lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp
  llvm/lib/Target/X86/X86ISelLowering.cpp
  llvm/test/Analysis/CostModel/X86/arith-fp.ll
  llvm/test/CodeGen/X86/frem-libcall.ll
  llvm/test/CodeGen/X86/frem.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D125988.430716.patch
Type: text/x-patch
Size: 95901 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220519/36c3c7ba/attachment-0001.bin>


More information about the llvm-commits mailing list