From 7877b51ba41955a65b49157d7ee9d7e1c47f7eb9 Mon Sep 17 00:00:00 2001 From: Akira Hatanaka Date: Thu, 18 Sep 2014 21:58:54 +0000 Subject: [PATCH] [X86, inlineasm] Do not allow using constraint 'x' for a variable larger than 128-bit unless the target CPU supports AVX. rdar://problem/11846140 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@218082 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Basic/Targets.cpp | 3 ++- test/CodeGen/x86_32-inline-asm.c | 11 +++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/Basic/Targets.cpp b/lib/Basic/Targets.cpp index 7f30ac551b..b4b8ec007d 100644 --- a/lib/Basic/Targets.cpp +++ b/lib/Basic/Targets.cpp @@ -3084,7 +3084,8 @@ bool X86TargetInfo::validateOperandSize(StringRef Constraint, case 'u': return Size <= 128; case 'x': - return Size <= 256; + // 256-bit ymm registers can be used if target supports AVX. + return Size <= (SSELevel >= AVX ? 256 : 128); } return true; diff --git a/test/CodeGen/x86_32-inline-asm.c b/test/CodeGen/x86_32-inline-asm.c index 25745212e9..c1fba0eee9 100644 --- a/test/CodeGen/x86_32-inline-asm.c +++ b/test/CodeGen/x86_32-inline-asm.c @@ -1,4 +1,5 @@ // RUN: %clang_cc1 -triple i386-apple-darwin9 -verify %s +// RUN: %clang_cc1 -triple i386-apple-darwin9 -target-feature +avx -verify %s // // rdar://problem/11846140 @@ -45,7 +46,6 @@ int func1() { __asm__ volatile("foo1 %0" : : "f" (val256)); // expected-error {{invalid input size for constraint 'f'}} __asm__ volatile("foo1 %0" : : "t" (val256)); // expected-error {{invalid input size for constraint 't'}} __asm__ volatile("foo1 %0" : : "u" (val256)); // expected-error {{invalid input size for constraint 'u'}} - __asm__ volatile("foo1 %0" : : "x" (val256)); // No error. __asm__ volatile("foo1 %0" : : "x" (val512)); // expected-error {{invalid input size for constraint 'x'}} __asm__ volatile("foo1 %0" : "=R" (val)); // expected-error {{invalid output size for constraint '=R'}} @@ -60,6 +60,13 @@ int func1() { __asm__ volatile("foo1 %0" : "=A" (val128)); // expected-error {{invalid output size for constraint '=A'}} __asm__ volatile("foo1 %0" : "=t" (val256)); // expected-error {{invalid output size for constraint '=t'}} __asm__ volatile("foo1 %0" : "=u" (val256)); // expected-error {{invalid output size for constraint '=u'}} - __asm__ volatile("foo1 %0" : "=x" (val256)); // No error. __asm__ volatile("foo1 %0" : "=x" (val512)); // expected-error {{invalid output size for constraint '=x'}} + +#ifdef __AVX__ + __asm__ volatile("foo1 %0" : : "x" (val256)); // No error. + __asm__ volatile("foo1 %0" : "=x" (val256)); // No error. +#else + __asm__ volatile("foo1 %0" : : "x" (val256)); // expected-error {{invalid input size for constraint 'x'}} + __asm__ volatile("foo1 %0" : "=x" (val256)); // expected-error {{invalid output size for constraint '=x'}} +#endif } -- 2.40.0