Skip to content

Commit ea6ac87

Browse files
committed
[CodeGen] Allow mixed scalar type constraints for inline asm
1 parent f025e41 commit ea6ac87

File tree

3 files changed

+42
-4
lines changed

3 files changed

+42
-4
lines changed

llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8841,8 +8841,11 @@ static void patchMatchingInput(const SDISelAsmOperandInfo &OpInfo,
88418841
std::pair<unsigned, const TargetRegisterClass *> InputRC =
88428842
TLI.getRegForInlineAsmConstraint(TRI, MatchingOpInfo.ConstraintCode,
88438843
MatchingOpInfo.ConstraintVT);
8844-
if ((OpInfo.ConstraintVT.isInteger() !=
8845-
MatchingOpInfo.ConstraintVT.isInteger()) ||
8844+
const bool OutOpIsIntOrFP =
8845+
OpInfo.ConstraintVT.isInteger() || OpInfo.ConstraintVT.isFloatingPoint();
8846+
const bool InOpInfoIsIntOrFP = MatchingOpInfo.ConstraintVT.isInteger() ||
8847+
MatchingOpInfo.ConstraintVT.isFloatingPoint();
8848+
if ((OutOpIsIntOrFP != InOpInfoIsIntOrFP) ||
88468849
(MatchRC.second != InputRC.second)) {
88478850
// FIXME: error out in a more elegant fashion
88488851
report_fatal_error("Unsupported asm: input constraint"

llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5687,8 +5687,11 @@ TargetLowering::ParseConstraints(const DataLayout &DL,
56875687
std::pair<unsigned, const TargetRegisterClass *> InputRC =
56885688
getRegForInlineAsmConstraint(TRI, Input.ConstraintCode,
56895689
Input.ConstraintVT);
5690-
if ((OpInfo.ConstraintVT.isInteger() !=
5691-
Input.ConstraintVT.isInteger()) ||
5690+
const bool OutOpIsIntOrFP = OpInfo.ConstraintVT.isInteger() ||
5691+
OpInfo.ConstraintVT.isFloatingPoint();
5692+
const bool InOpIsIntOrFP = Input.ConstraintVT.isInteger() ||
5693+
Input.ConstraintVT.isFloatingPoint();
5694+
if ((OutOpIsIntOrFP != InOpIsIntOrFP) ||
56925695
(MatchRC.second != InputRC.second)) {
56935696
report_fatal_error("Unsupported asm: input constraint"
56945697
" with a matching output constraint of"
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2+
; RUN: llc -mtriple=x86_64-unknown-linux-gnu < %s | FileCheck %s
3+
4+
; C source used for generating this test:
5+
6+
; unsigned test(float f)
7+
; {
8+
; unsigned i;
9+
; asm volatile ("" : "=r" (i) : "0" (f));
10+
; return i;
11+
; }
12+
13+
14+
define i32 @test(float %f) {
15+
; CHECK-LABEL: test:
16+
; CHECK: # %bb.0: # %entry
17+
; CHECK-NEXT: movss %xmm0, -{{[0-9]+}}(%rsp)
18+
; CHECK-NEXT: movl -{{[0-9]+}}(%rsp), %eax
19+
; CHECK-NEXT: #APP
20+
; CHECK-NEXT: #NO_APP
21+
; CHECK-NEXT: movl %eax, -{{[0-9]+}}(%rsp)
22+
; CHECK-NEXT: retq
23+
entry:
24+
%f.addr = alloca float, align 4
25+
%i = alloca i32, align 4
26+
store float %f, ptr %f.addr, align 4
27+
%0 = load float, ptr %f.addr, align 4
28+
%1 = call i32 asm sideeffect "", "=r,0,~{dirflag},~{fpsr},~{flags}"(float %0)
29+
store i32 %1, ptr %i, align 4
30+
%2 = load i32, ptr %i, align 4
31+
ret i32 %2
32+
}

0 commit comments

Comments
 (0)