[clang] Update test intrinsic to support immediates (PR #79174)

via cfe-commits cfe-commits at lists.llvm.org
Tue Jan 23 09:33:03 PST 2024


https://github.com/AtariDreams created https://github.com/llvm/llvm-project/pull/79174

None

>From 9ed2a138bd980c1c043e1585cb8e5d82a1592f1e Mon Sep 17 00:00:00 2001
From: Rose <83477269+AtariDreams at users.noreply.github.com>
Date: Tue, 23 Jan 2024 12:31:49 -0500
Subject: [PATCH] Update test intrinsic to support immediates

---
 clang/lib/CodeGen/CGBuiltin.cpp | 20 +++++++++++++++++---
 1 file changed, 17 insertions(+), 3 deletions(-)

diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 7ef764b8e1ac80e..e404f92c284aafc 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -1203,10 +1203,24 @@ static llvm::Value *EmitX86BitTestIntrinsic(CodeGenFunction &CGF,
   AsmOS << "bt";
   if (Action)
     AsmOS << Action;
-  AsmOS << SizeSuffix << " $2, ($1)";
 
-  // Build the constraints. FIXME: We should support immediates when possible.
-  std::string Constraints = "={@ccc},r,r,~{cc},~{memory}";
+  // Check if BitPos is a ConstantInt (immediate value)
+  if (llvm::ConstantInt *CI = llvm::dyn_cast<llvm::ConstantInt>(BitPos)) {
+    // If it is, use the immediate value in the assembly string
+    AsmOS << SizeSuffix << " $" << CI->getZExtValue() << ", ($1)";
+  } else {
+    // Otherwise, fall back to the existing behavior
+    AsmOS << SizeSuffix << " $2, ($1)";
+  }
+
+  // Build the constraints.
+  std::string Constraints;
+  if (llvm::isa<llvm::ConstantInt>(BitPos)) {
+    Constraints = "={@ccc},r,~{cc},~{memory}";
+  } else {
+    Constraints = "={@ccc},r,r,~{cc},~{memory}";
+  }
+  
   std::string_view MachineClobbers = CGF.getTarget().getClobbers();
   if (!MachineClobbers.empty()) {
     Constraints += ',';



More information about the cfe-commits mailing list