Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CodeGen] Update test intrinsic to support immediates #79174

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

AtariDreams
Copy link
Contributor

No description provided.

@llvmbot llvmbot added clang Clang issues not falling into any other category clang:codegen labels Jan 23, 2024
@llvmbot
Copy link
Collaborator

llvmbot commented Jan 23, 2024

@llvm/pr-subscribers-clang

@llvm/pr-subscribers-clang-codegen

Author: AtariDreams (AtariDreams)

Changes

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

1 Files Affected:

  • (modified) clang/lib/CodeGen/CGBuiltin.cpp (+17-3)
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 += ',';

Copy link

github-actions bot commented Jan 23, 2024

✅ With the latest revision this PR passed the C/C++ code formatter.

@AtariDreams AtariDreams changed the title Update test intrinsic to support immediates [CodeGen] Update test intrinsic to support immediates Feb 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:codegen clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants