[PATCH] D56990: Bugfix for Replacement of tied operand of inline asm

Xiang Zhang via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sun Jan 20 17:21:46 PST 2019


xiangzhangllvm created this revision.
xiangzhangllvm added reviewers: craig.topper, smaslov, LuoYuanke.
xiangzhangllvm added a project: clang.
Herald added subscribers: cfe-commits, eraman.

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 ));

test case:

typedef unsigned char _attribute_((vector_size(8))) _m64u8;
static int _isFailed = 0;

int main(void){
 _m64u8 __attribute__((aligned(16))) Mu8_0, __attribute__((aligned(16))) Mu8_1;
 asm ("nop" : "=y"(Mu8_1 ) : "0"(Mu8_0 ));
 return 0;
 }


Repository:
  rC Clang

https://reviews.llvm.org/D56990

Files:
  lib/CodeGen/CGStmt.cpp
  test/Sema/inline-asm-x86-constraint.c


Index: test/Sema/inline-asm-x86-constraint.c
===================================================================
--- /dev/null
+++ test/Sema/inline-asm-x86-constraint.c
@@ -0,0 +1,9 @@
+// REQUIRES: x86-registered-target
+// RUN: %clang_cc1  %s -o %t
+typedef unsigned char __attribute__((vector_size(8))) _m64u8;
+
+int main(void) {
+  _m64u8 __attribute__((aligned(16))) Mu8_0, __attribute__((aligned(16))) Mu8_1;
+  asm ("nop" : "=y"(Mu8_1 ) : "0"(Mu8_0 ));
+  return 0;
+}
Index: lib/CodeGen/CGStmt.cpp
===================================================================
--- lib/CodeGen/CGStmt.cpp
+++ lib/CodeGen/CGStmt.cpp
@@ -1915,6 +1915,9 @@
   std::vector<llvm::Value*> InOutArgs;
   std::vector<llvm::Type*> InOutArgTypes;
 
+  // Keep track of out constraints for tied input operand.
+  std::vector<std::string> OutputConstraints;
+
   // An inline asm can be marked readonly if it meets the following conditions:
   //  - it doesn't have any sideeffects
   //  - it doesn't clobber memory
@@ -1937,7 +1940,7 @@
     OutputConstraint = AddVariableConstraints(OutputConstraint, *OutExpr,
                                               getTarget(), CGM, S,
                                               Info.earlyClobber());
-
+    OutputConstraints.push_back(OutputConstraint);
     LValue Dest = EmitLValue(OutExpr);
     if (!Constraints.empty())
       Constraints += ',';
@@ -2055,6 +2058,7 @@
         InputConstraint, *InputExpr->IgnoreParenNoopCasts(getContext()),
         getTarget(), CGM, S, false /* No EarlyClobber */);
 
+    std::string ReplaceConstraint (InputConstraint);
     llvm::Value *Arg = EmitAsmInput(Info, InputExpr, Constraints);
 
     // If this input argument is tied to a larger output result, extend the
@@ -2082,9 +2086,11 @@
           Arg = Builder.CreateFPExt(Arg, OutputTy);
         }
       }
+      // Deal with the tied operands' constraint code in adjustInlineAsmType.
+      ReplaceConstraint = OutputConstraints[Output];
     }
     if (llvm::Type* AdjTy =
-              getTargetHooks().adjustInlineAsmType(*this, InputConstraint,
+          getTargetHooks().adjustInlineAsmType(*this, ReplaceConstraint,
                                                    Arg->getType()))
       Arg = Builder.CreateBitCast(Arg, AdjTy);
     else


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D56990.182729.patch
Type: text/x-patch
Size: 2289 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190121/12ad911c/attachment.bin>


More information about the cfe-commits mailing list