Skip to content

Commit

Permalink
[Sparc] Use float register for integer constrained with "f" in inline…
Browse files Browse the repository at this point in the history
… asm

Summary:
Constraining an integer value to a floating point register using "f"
causes an llvm_unreachable to trigger. This patch allows i32 integers
to be placed in a single precision float register and i64 integers to
be placed in a double precision float register. This matches the behavior
of GCC.

For other types the llvm_unreachable is removed to instead trigger an
error message that points out the offending line.

Reviewers: jyknight, venkatra

Reviewed By: jyknight

Subscribers: eraman, fedor.sergeev, jrtc27, llvm-commits

Differential Revision: https://reviews.llvm.org/D51614

llvm-svn: 349045
  • Loading branch information
doac committed Dec 13, 2018
1 parent c7b43b9 commit b5d2844
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
16 changes: 8 additions & 8 deletions llvm/lib/Target/Sparc/SparcISelLowering.cpp
Expand Up @@ -3261,23 +3261,23 @@ SparcTargetLowering::getRegForInlineAsmConstraint(const TargetRegisterInfo *TRI,
else
return std::make_pair(0U, &SP::IntRegsRegClass);
case 'f':
if (VT == MVT::f32)
if (VT == MVT::f32 || VT == MVT::i32)
return std::make_pair(0U, &SP::FPRegsRegClass);
else if (VT == MVT::f64)
else if (VT == MVT::f64 || VT == MVT::i64)
return std::make_pair(0U, &SP::LowDFPRegsRegClass);
else if (VT == MVT::f128)
return std::make_pair(0U, &SP::LowQFPRegsRegClass);
llvm_unreachable("Unknown ValueType for f-register-type!");
break;
// This will generate an error message
return std::make_pair(0U, nullptr);
case 'e':
if (VT == MVT::f32)
if (VT == MVT::f32 || VT == MVT::i32)
return std::make_pair(0U, &SP::FPRegsRegClass);
else if (VT == MVT::f64)
else if (VT == MVT::f64 || VT == MVT::i64 )
return std::make_pair(0U, &SP::DFPRegsRegClass);
else if (VT == MVT::f128)
return std::make_pair(0U, &SP::QFPRegsRegClass);
llvm_unreachable("Unknown ValueType for e-register-type!");
break;
// This will generate an error message
return std::make_pair(0U, nullptr);
}
} else if (!Constraint.empty() && Constraint.size() <= 5
&& Constraint[0] == '{' && *(Constraint.end()-1) == '}') {
Expand Down
13 changes: 13 additions & 0 deletions llvm/test/CodeGen/SPARC/inlineasm.ll
Expand Up @@ -130,3 +130,16 @@ entry:
tail call void asm sideeffect "faddd $0,$1,$2", "{f20},{f20},{f20}"(double 9.0, double 10.0, double 11.0)
ret void
}

; CHECK-LABEL: test_constraint_f_e_i32_i64:
; CHECK: ld [%o0+%lo(.LCPI13_0)], %f0
; CHECK: ldd [%o0+%lo(.LCPI13_1)], %f2
; CHECK: fadds %f0, %f0, %f0
; CHECK: faddd %f2, %f2, %f0

define void @test_constraint_f_e_i32_i64() {
entry:
%0 = call float asm sideeffect "fadds $1, $2, $0", "=f,f,e"(i32 0, i32 0)
%1 = call double asm sideeffect "faddd $1, $2, $0", "=f,f,e"(i64 0, i64 0)
ret void
}

0 comments on commit b5d2844

Please sign in to comment.