This is an archive of the discontinued LLVM Phabricator instance.

Fix crash on inline asm with 64bit matching input in 32bit GPR
ClosedPublic

Authored by thopre on Jun 21 2018, 8:00 AM.

Details

Summary

Add support for inline assembly with matching input operand that do not naturally go in the register class it is constrained to (eg. double in a 32-bit GPR). Note that regular input is already handled by existing code.

Diff Detail

Event Timeline

thopre created this revision.Jun 21 2018, 8:00 AM
thopre updated this revision to Diff 156998.Jul 24 2018, 4:07 AM

Rename testcase and test both soft and hard float ABI

efriedma added inline comments.Jul 24 2018, 5:23 PM
lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
7222

I don't follow this... don't we need to allocate virtual registers anyway? And how is this relevant to this patch?

7471–7472

Why is this "OpInfo.ConstraintType == TargetLowering::C_Register" here, but "RefOpInfo.ConstraintType == TargetLowering::C_RegisterClass" later?

thopre added inline comments.Jul 26 2018, 3:06 AM
lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
7222

The virtual register is allocated later at line 7599 with the patch applied when "looping over all of the inputs, copying the operand values into the appropriate registers and processing the output regs" (dixit comment). That code was already there before any of my patch and I decided to keep that code structure.

It is relevant to this patch because prior to it GetRegistersForValue was not called for matching input since it was only called for C_RegisterClass constraints. It is now called for matching input as well since that is where is the logic to deal with mismatch between register constraint size and the operand type.

7471–7472

I didn't write these two checks but from the comment above the goal seems to distinguish between constraints for specific register (C_Register) from general register constraint (C_RegisterClass). Allocating registers for the former before the latter avoids allocating register X to a general register constraint and later dealing with a constraint asking for X specifically when there was a register Y which the general constraint would have been happy with.

efriedma added inline comments.Jul 26 2018, 11:13 AM
lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
7471–7472

Sorry, I wasn't clear; why is the first check checking OpInfo, and the second checking RefOpInfo?

thopre updated this revision to Diff 157785.Jul 27 2018, 3:08 PM

Fix logic for input matching a register constraint for a specific register and add tests for it. I've verified that the code for this logic is executed by those new testcases and that the testcase failed without the fix.

thopre added inline comments.Jul 27 2018, 3:11 PM
lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
7471–7472

Good catch! I've fixed this and added testcases for this cases and confirmed that they failed when using OpInfo.

This revision is now accepted and ready to land.Jul 27 2018, 4:18 PM
thopre closed this revision.Aug 8 2018, 2:42 AM