Skip to content

Commit e59a619

Browse files
authored
Clang: don't unnecessarily convert inline-asm operands to x86mmx in IR. (#98273)
The SelectionDAG asm-lowering code can already handle conversion of other vector types to MMX if needed.
1 parent 43ca631 commit e59a619

File tree

5 files changed

+47
-22
lines changed

5 files changed

+47
-22
lines changed

clang/lib/CodeGen/Targets/X86.cpp

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,9 @@ bool IsX86_MMXType(llvm::Type *IRType) {
2424
IRType->getScalarSizeInBits() != 64;
2525
}
2626

27-
static llvm::Type* X86AdjustInlineAsmType(CodeGen::CodeGenFunction &CGF,
27+
static llvm::Type *X86AdjustInlineAsmType(CodeGen::CodeGenFunction &CGF,
2828
StringRef Constraint,
29-
llvm::Type* Ty) {
30-
bool IsMMXCons = llvm::StringSwitch<bool>(Constraint)
31-
.Cases("y", "&y", "^Ym", true)
32-
.Default(false);
33-
if (IsMMXCons && Ty->isVectorTy()) {
34-
if (cast<llvm::VectorType>(Ty)->getPrimitiveSizeInBits().getFixedValue() !=
35-
64) {
36-
// Invalid MMX constraint
37-
return nullptr;
38-
}
39-
40-
return llvm::Type::getX86_MMXTy(CGF.getLLVMContext());
41-
}
42-
29+
llvm::Type *Ty) {
4330
if (Constraint == "k") {
4431
llvm::Type *Int1Ty = llvm::Type::getInt1Ty(CGF.getLLVMContext());
4532
return llvm::FixedVectorType::get(Int1Ty, Ty->getScalarSizeInBits());

clang/test/CodeGen/X86/mmx-inline-asm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// RUN: %clang_cc1 -emit-llvm -triple i386 -target-feature +mmx %s -o - | FileCheck %s
22
#include <mmintrin.h>
33

4-
// CHECK: { x86_mmx, x86_mmx, x86_mmx, x86_mmx, x86_mmx, x86_mmx, x86_mmx }
4+
// CHECK: { <1 x i64>, <1 x i64>, <1 x i64>, <1 x i64>, <1 x i64>, <1 x i64>, <1 x i64> }
55

66
void foo(long long fill) {
77
__m64 vfill = _mm_cvtsi64_m64(fill);

clang/test/CodeGen/asm-inout.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@ int test4(volatile int *addr) {
3838
return (int)oldval;
3939
}
4040

41-
// This should have both inputs be of type x86_mmx.
41+
// This should have both inputs be of type <1 x i64>.
4242
// CHECK: @test5
4343
typedef long long __m64 __attribute__((__vector_size__(8)));
4444
__m64 test5(__m64 __A, __m64 __B) {
45-
// CHECK: call x86_mmx asm "pmulhuw $1, $0\0A\09", "=y,y,0,~{dirflag},~{fpsr},~{flags}"(x86_mmx %{{.*}}, x86_mmx %{{.*}})
45+
// CHECK: call <1 x i64> asm "pmulhuw $1, $0\0A\09", "=y,y,0,~{dirflag},~{fpsr},~{flags}"(<1 x i64> %{{.*}}, <1 x i64> %{{.*}})
4646
asm ("pmulhuw %1, %0\n\t" : "+y" (__A) : "y" (__B));
4747
return __A;
4848
}
@@ -51,7 +51,7 @@ __m64 test5(__m64 __A, __m64 __B) {
5151
int test6(void) {
5252
typedef unsigned char __attribute__((vector_size(8))) _m64u8;
5353
_m64u8 __attribute__((aligned(16))) Mu8_0, __attribute__((aligned(16))) Mu8_1;
54-
// CHECK: call x86_mmx asm "nop", "=y,0,~{dirflag},~{fpsr},~{flags}"(x86_mmx %1)
54+
// CHECK: call <8 x i8> asm "nop", "=y,0,~{dirflag},~{fpsr},~{flags}"(<8 x i8> %0)
5555
asm ("nop" : "=y"(Mu8_1 ) : "0"(Mu8_0 ));
5656
return 0;
5757
}

llvm/lib/Target/X86/X86ISelLowering.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58378,7 +58378,7 @@ X86TargetLowering::getSingleConstraintMatchWeight(
5837858378
Wt = CW_SpecificReg;
5837958379
break;
5838058380
case 'y':
58381-
if (Ty->isX86_MMXTy() && Subtarget.hasMMX())
58381+
if (Ty->getPrimitiveSizeInBits() == 64 && Subtarget.hasMMX())
5838258382
Wt = CW_SpecificReg;
5838358383
break;
5838458384
case 'Y':
@@ -58401,8 +58401,8 @@ X86TargetLowering::getSingleConstraintMatchWeight(
5840158401
return CW_Invalid;
5840258402
// Any MMX reg
5840358403
case 'm':
58404-
if (Ty->isX86_MMXTy() && Subtarget.hasMMX())
58405-
return Wt;
58404+
if (Ty->getPrimitiveSizeInBits() == 64 && Subtarget.hasMMX())
58405+
return CW_SpecificReg;
5840658406
return CW_Invalid;
5840758407
// Any SSE reg when ISA >= SSE2, same as 'x'
5840858408
case 'i':
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5
2+
; RUN: llc < %s -mtriple=x86_64-unknown-unknown -mattr=+mmx | FileCheck %s
3+
4+
;; Verify that the mmx 'y' constraint works with arbitrary IR types.
5+
define <2 x i32> @test_mmx_asm(<2 x i32> %a) nounwind {
6+
; CHECK-LABEL: test_mmx_asm:
7+
; CHECK: # %bb.0:
8+
; CHECK-NEXT: movdq2q %xmm0, %mm0
9+
; CHECK-NEXT: #APP
10+
; CHECK-NEXT: # %mm0 = %mm0
11+
; CHECK-NEXT: #NO_APP
12+
; CHECK-NEXT: #APP
13+
; CHECK-NEXT: # %mm0 = %mm0
14+
; CHECK-NEXT: #NO_APP
15+
; CHECK-NEXT: movq2dq %mm0, %xmm0
16+
; CHECK-NEXT: retq
17+
%1 = tail call i64 asm sideeffect "# $0 = $1", "=y,y"(<2 x i32> %a)
18+
%2 = tail call <2 x i32> asm sideeffect "# $0 = $1", "=y,y"(i64 %1)
19+
ret <2 x i32> %2
20+
}
21+
22+
;; And same thing with the 'Ym' constraint.
23+
define <2 x i32> @test_mmx_asm_Ym(<2 x i32> %a) nounwind {
24+
; CHECK-LABEL: test_mmx_asm_Ym:
25+
; CHECK: # %bb.0:
26+
; CHECK-NEXT: movdq2q %xmm0, %mm0
27+
; CHECK-NEXT: #APP
28+
; CHECK-NEXT: # %mm0 = %mm0
29+
; CHECK-NEXT: #NO_APP
30+
; CHECK-NEXT: #APP
31+
; CHECK-NEXT: # %mm0 = %mm0
32+
; CHECK-NEXT: #NO_APP
33+
; CHECK-NEXT: movq2dq %mm0, %xmm0
34+
; CHECK-NEXT: retq
35+
%1 = tail call i64 asm sideeffect "# $0 = $1", "=^Ym,^Ym"(<2 x i32> %a)
36+
%2 = tail call <2 x i32> asm sideeffect "# $0 = $1", "=^Ym,^Ym"(i64 %1)
37+
ret <2 x i32> %2
38+
}

0 commit comments

Comments
 (0)