This is an archive of the discontinued LLVM Phabricator instance.

Use correct registers for "A" inline asm constraint
ClosedPublic

Authored by dim on Apr 10 2017, 12:10 PM.

Details

Summary

In PR32594, inline assembly using the 'A' constraint on x86_64 causes
llvm to crash with a "Cannot select" stack trace. This is because
X86TargetLowering::getRegForInlineAsmConstraint hardcodes that 'A'
means the EAX and EDX registers.

However, on x86_64 it means the RAX and RDX registers, and on 16-bit x86
(ia16?) it means the old AX and DX registers.

Add new register classes in X86RegisterInfo.td to support these cases,
and amend the logic in getRegForInlineAsmConstraint to cope with
different subtargets. Also add a test case, derived from PR32594.

Event Timeline

dim created this revision.Apr 10 2017, 12:10 PM
dim updated this revision to Diff 94715.Apr 10 2017, 12:13 PM

Remove extraneous space at the end of llvm_unreachable.

dim added a comment.Apr 12 2017, 1:20 AM

Minor ping, since I am unsure whether any of Phab's emails were lost in the recent outage.

ab accepted this revision.Apr 13 2017, 1:59 AM
ab added a subscriber: ab.

LGTM, thanks!

16-bit is weird, but it'd be great if you could add a testcase for that.

test/CodeGen/X86/inline-asm-A-constraint.ll
1

'-march=x86_64' -> '-mtriple=x86_64--' ? Helps avoid sensitivity to the host (not that it matters in this file) and lets you get rid of the IR triple.

Also, '-no-integrated-as' doesn't have an effect here, right?

9

Can you add CHECK lines for the generated asm?

This revision is now accepted and ready to land.Apr 13 2017, 1:59 AM
dim added inline comments.Apr 13 2017, 2:47 PM
test/CodeGen/X86/inline-asm-A-constraint.ll
1

I copied this example from other inline asm tests, most of which seem to use -no-integrated-as. I'm not sure why that was done, maybe because in some cases invalid mnemonics (e.g. foo) are used, and that could trip up the test?

Similar for the -march flag, most test cases seem to use plain x86_64. But it's a good idea to remove host influences, thanks.

9

Since the asm statement is completely empty, there is nothing generated except #APP and #NO_APP. Does it make sense to check for that?

dim updated this revision to Diff 95304.Apr 14 2017, 8:26 AM

Address comments by changing the test case to something more explicit, derived from PR32594.

This uses x86_64-- as triple, and checks the resulting assembly.

dim closed this revision.Apr 15 2017, 3:27 PM