This is an archive of the discontinued LLVM Phabricator instance.

[X86] Add support for using fast short rep mov for memcpy lowering.
ClosedPublic

Authored by hjyamauchi on Aug 31 2020, 10:31 AM.

Details

Diff Detail

Event Timeline

hjyamauchi created this revision.Aug 31 2020, 10:31 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 31 2020, 10:31 AM
Herald added a subscriber: hiraditya. · View Herald Transcript
hjyamauchi requested review of this revision.Aug 31 2020, 10:31 AM
craig.topper added inline comments.Aug 31 2020, 10:47 AM
llvm/lib/Target/X86/X86SelectionDAGInfo.cpp
198

Is this needed because we're no longer calling this with just constants we fixed the size of?

hjyamauchi added inline comments.Sep 2 2020, 9:49 AM
llvm/lib/Target/X86/X86SelectionDAGInfo.cpp
198

Do you mean, "is the getCopyToReg call needed"? The size needs to be loaded into the RCX/ECX register for the rep movs instruction and the callers aren't doing that. So, it seems yes. Did you mean in a different way?

craig.topper added inline comments.Sep 2 2020, 9:57 AM
llvm/lib/Target/X86/X86SelectionDAGInfo.cpp
198

I was asking why the getZExtOrTrunc was added. do we create memcpy's where the size type isn't the same size as the pointer?

hjyamauchi added inline comments.Sep 2 2020, 10:41 AM
llvm/lib/Target/X86/X86SelectionDAGInfo.cpp
198

Without the getZExtOrTrunc, I get this fatal error, for example,

Cannot copy EAX to RCX
fatal error: error in backend: Cannot emit physreg copy instruction

which is coming from X86InstrInfo::copyPhysReg.

Re: "do we create memcpy's where the size type isn't the same size as the pointer?" yes, it seems so.

hjyamauchi added inline comments.Sep 2 2020, 12:51 PM
llvm/lib/Target/X86/X86SelectionDAGInfo.cpp
198

The type mismatch is coming from here:

static SDValue CreateCopyOfByValArgument(SDValue Src, SDValue Dst,
                                         SDValue Chain, ISD::ArgFlagsTy Flags,
                                         SelectionDAG &DAG, const SDLoc &dl) {
  SDValue SizeNode = DAG.getConstant(Flags.getByValSize(), dl, MVT::i32);
  ...

I'm going to fix that instead.

Update to remove the getZExtOrTrunc.

craig.topper added inline comments.Sep 2 2020, 1:12 PM
llvm/lib/Target/X86/X86ISelLowering.cpp
3112

Maybe just use getIntPtrConstant instead of getConstant?

llvm/lib/Target/X86/X86SelectionDAGInfo.cpp
198

Does that occur with the included test case or some other testing?

hjyamauchi updated this revision to Diff 289567.Sep 2 2020, 2:23 PM

Address comments.

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

My bad. This should actually be an int const rather than an int pointer const. Will change it to check if it's 64 bit instead.

llvm/lib/Target/X86/X86SelectionDAGInfo.cpp
198

It occurs in a clang bootstrap build. Added a reduced test below.

craig.topper added inline comments.Sep 2 2020, 2:27 PM
llvm/lib/Target/X86/X86ISelLowering.cpp
3112

IntPtrConstant is an integer the width of a pointer which I think is what we want.

You can't check for i64 being legal. That doesn't work for GNUX32 or NaCl which use 32-bit pointers on 64 bit.

Address comment.

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

Done.

This revision is now accepted and ready to land.Sep 9 2020, 12:36 PM
This revision was landed with ongoing or failed builds.Sep 9 2020, 12:47 PM
This revision was automatically updated to reflect the committed changes.