This is an archive of the discontinued LLVM Phabricator instance.

[X86] Teach X86SelectionDAGInfo::EmitTargetCodeForMemcpy about GNUX32
ClosedPublic

Authored by craig.topper on Sep 10 2018, 3:25 PM.

Details

Summary

In GNUX23, is64BitMode returns true, but pointers are 32-bits. So we shouldn't copy pointer values into RSI/RDI since the widths don't match.

Fixes PR38865 despite what the title says. I think the llvm_unreachable in the copyPhysReg code tricked the optimizer and made the fatal error trigger.

Diff Detail

Repository
rL LLVM

Event Timeline

craig.topper created this revision.Sep 10 2018, 3:25 PM
efriedma added inline comments.Sep 11 2018, 12:14 PM
test/CodeGen/X86/pr38865.ll
24 ↗(On Diff #164757)

Shouldn't this be rep;movsl (%esi), (%edi), to get the right encoding?

craig.topper added inline comments.Sep 11 2018, 12:23 PM
test/CodeGen/X86/pr38865.ll
24 ↗(On Diff #164757)

Are you saying we should be using the 0x67 adsize prefix?

efriedma added inline comments.Sep 11 2018, 12:40 PM
test/CodeGen/X86/pr38865.ll
24 ↗(On Diff #164757)

Yes, to be consistent with other memory operations.

Use 0x67 address size prefix for x32. Don't disable movsq with x32.

To make the 0x67 work I had to add AdSize32 and AdSize64 to the CodeGenOnly instructions we use here. These control bits in TSFlags. The encoder will emit a 0x67 when the AdSize value is different than the current mode. I had to do it this way because these instructions aren't carrying any operands once they reach the MC layer so there is nothing else for the encoder to key off of.

I've also altered the Predicates to use IsLP64 and NotLP64 to choose the address size instead of just the mode.

Finally I altered the strings printed by the AsmWriter to explicitly mention the register names so that we will still generate a 0x67 prefix if the assembly is written to a text file and then fed to an assembler to generate a binary. I believe gcc would use an "addr32" prefix here, but I'm not sure our assembler supprots that.

I believe we have the same bug for memset as well, but I'd prefer to tackle that as a follow up since I don't have a test case yet.

efriedma accepted this revision.Sep 11 2018, 5:02 PM

LGTM

lib/Target/X86/X86InstrCompiler.td
412 ↗(On Diff #165000)

Probably should be Requires<[NotLP64, In64BitMode]>, for the sake of clarity.

This revision is now accepted and ready to land.Sep 11 2018, 5:02 PM
This revision was automatically updated to reflect the committed changes.