Skip to content

Commit 4af1c26

Browse files
committed
[CodeGen] Consider tied operands when adjusting inline asm operands.
The constraint "0" in the following asm did not consider the its relationship with "=y" when try to replace the type of the operands. asm ("nop" : "=y"(Mu8_1 ) : "0"(Mu8_0 )); Patch by Xiang Zhang. Differential Revision: https://reviews.llvm.org/D56990 llvm-svn: 356196
1 parent 38f07b1 commit 4af1c26

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

clang/lib/CodeGen/CGStmt.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1939,6 +1939,9 @@ void CodeGenFunction::EmitAsmStmt(const AsmStmt &S) {
19391939
std::vector<llvm::Value*> InOutArgs;
19401940
std::vector<llvm::Type*> InOutArgTypes;
19411941

1942+
// Keep track of out constraints for tied input operand.
1943+
std::vector<std::string> OutputConstraints;
1944+
19421945
// An inline asm can be marked readonly if it meets the following conditions:
19431946
// - it doesn't have any sideeffects
19441947
// - it doesn't clobber memory
@@ -1961,7 +1964,7 @@ void CodeGenFunction::EmitAsmStmt(const AsmStmt &S) {
19611964
OutputConstraint = AddVariableConstraints(OutputConstraint, *OutExpr,
19621965
getTarget(), CGM, S,
19631966
Info.earlyClobber());
1964-
1967+
OutputConstraints.push_back(OutputConstraint);
19651968
LValue Dest = EmitLValue(OutExpr);
19661969
if (!Constraints.empty())
19671970
Constraints += ',';
@@ -2079,6 +2082,7 @@ void CodeGenFunction::EmitAsmStmt(const AsmStmt &S) {
20792082
InputConstraint, *InputExpr->IgnoreParenNoopCasts(getContext()),
20802083
getTarget(), CGM, S, false /* No EarlyClobber */);
20812084

2085+
std::string ReplaceConstraint (InputConstraint);
20822086
llvm::Value *Arg = EmitAsmInput(Info, InputExpr, Constraints);
20832087

20842088
// If this input argument is tied to a larger output result, extend the
@@ -2106,9 +2110,11 @@ void CodeGenFunction::EmitAsmStmt(const AsmStmt &S) {
21062110
Arg = Builder.CreateFPExt(Arg, OutputTy);
21072111
}
21082112
}
2113+
// Deal with the tied operands' constraint code in adjustInlineAsmType.
2114+
ReplaceConstraint = OutputConstraints[Output];
21092115
}
21102116
if (llvm::Type* AdjTy =
2111-
getTargetHooks().adjustInlineAsmType(*this, InputConstraint,
2117+
getTargetHooks().adjustInlineAsmType(*this, ReplaceConstraint,
21122118
Arg->getType()))
21132119
Arg = Builder.CreateBitCast(Arg, AdjTy);
21142120
else

clang/test/CodeGen/asm-inout.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,12 @@ __m64 test5(__m64 __A, __m64 __B) {
4646
asm ("pmulhuw %1, %0\n\t" : "+y" (__A) : "y" (__B));
4747
return __A;
4848
}
49+
50+
// CHECK: @test6
51+
int test6(void) {
52+
typedef unsigned char __attribute__((vector_size(8))) _m64u8;
53+
_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)
55+
asm ("nop" : "=y"(Mu8_1 ) : "0"(Mu8_0 ));
56+
return 0;
57+
}

0 commit comments

Comments
 (0)