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

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


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang

@llvm/pr-subscribers-clang-codegen

Author: AtariDreams (AtariDreams)

<details>
<summary>Changes</summary>



---
Full diff: https://github.com/llvm/llvm-project/pull/79174.diff


1 Files Affected:

- (modified) clang/lib/CodeGen/CGBuiltin.cpp (+17-3) 


``````````diff
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 7ef764b8e1ac80..e404f92c284aaf 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 += ',';

``````````

</details>


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


More information about the cfe-commits mailing list