https://github.com/dfszabo updated https://github.com/llvm/llvm-project/pull/65465
From 69e13118b0669b3e54c5fffc1f5ac60d8b6b2d62 Mon Sep 17 00:00:00 2001 From: dfszabo <szabodavidfer...@gmail.com> Date: Wed, 6 Sep 2023 13:07:19 +0200 Subject: [PATCH] [Clang] Allow mixed scalar type constraints for inline asm GCC supports code like "asm volatile ("" : "=r" (i) : "0" (f))" where i is integer type and f is floating point type. Currently this code produces an error with Clang. The change allows mixed scalar types between input and output constraints. --- clang/test/CodeGen/inline-asm-fp-to-int.c | 8 ++++++++ llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp | 7 +++++-- 2 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 clang/test/CodeGen/inline-asm-fp-to-int.c diff --git a/clang/test/CodeGen/inline-asm-fp-to-int.c b/clang/test/CodeGen/inline-asm-fp-to-int.c new file mode 100644 index 000000000000000..cdcdb4c90516a4b --- /dev/null +++ b/clang/test/CodeGen/inline-asm-fp-to-int.c @@ -0,0 +1,8 @@ +// RUN: %clang_cc1 %s -emit-llvm -o /dev/null + +unsigned test(float f) +{ + unsigned i; + asm volatile ("" : "=r" (i) : "0" (f)); + return i; +} diff --git a/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp b/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp index bd1940994a87f0f..50aec396c78b809 100644 --- a/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp @@ -5687,8 +5687,11 @@ TargetLowering::ParseConstraints(const DataLayout &DL, std::pair<unsigned, const TargetRegisterClass *> InputRC = getRegForInlineAsmConstraint(TRI, Input.ConstraintCode, Input.ConstraintVT); - if ((OpInfo.ConstraintVT.isInteger() != - Input.ConstraintVT.isInteger()) || + const bool OpInfoIsScalar = OpInfo.ConstraintVT.isInteger() || + OpInfo.ConstraintVT.isFloatingPoint(); + const bool InputIsScalar = Input.ConstraintVT.isInteger() || + Input.ConstraintVT.isFloatingPoint(); + if ((!OpInfoIsScalar && !InputIsScalar) || (MatchRC.second != InputRC.second)) { report_fatal_error("Unsupported asm: input constraint" " with a matching output constraint of" _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits