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

[NFC][clang] Replace unchecked dyn_cast with cast #98948

Merged
merged 1 commit into from
Jul 16, 2024

Conversation

mikerice1969
Copy link
Contributor

BI__builtin_hlsl_elementwise_rcp is only invoked with a FixedVectorType so use cast to make this clear and satisfy the static verifier.

BI__builtin_hlsl_elementwise_rcp is only invoked with a FixedVectorType
so use cast to make this clear and satisfy the static verifier.
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:codegen labels Jul 15, 2024
@llvmbot
Copy link
Collaborator

llvmbot commented Jul 15, 2024

@llvm/pr-subscribers-clang-codegen

@llvm/pr-subscribers-clang

Author: Mike Rice (mikerice1969)

Changes

BI__builtin_hlsl_elementwise_rcp is only invoked with a FixedVectorType so use cast to make this clear and satisfy the static verifier.


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

1 Files Affected:

  • (modified) clang/lib/CodeGen/CGBuiltin.cpp (+6-7)
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index a54fa7bf87aad..c0297476391d2 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -18389,13 +18389,12 @@ Value *CodeGenFunction::EmitHLSLBuiltinExpr(unsigned BuiltinID,
       llvm_unreachable("rcp operand must have a float representation");
     llvm::Type *Ty = Op0->getType();
     llvm::Type *EltTy = Ty->getScalarType();
-    Constant *One =
-        Ty->isVectorTy()
-            ? ConstantVector::getSplat(
-                  ElementCount::getFixed(
-                      dyn_cast<FixedVectorType>(Ty)->getNumElements()),
-                  ConstantFP::get(EltTy, 1.0))
-            : ConstantFP::get(EltTy, 1.0);
+    Constant *One = Ty->isVectorTy()
+                        ? ConstantVector::getSplat(
+                              ElementCount::getFixed(
+                                  cast<FixedVectorType>(Ty)->getNumElements()),
+                              ConstantFP::get(EltTy, 1.0))
+                        : ConstantFP::get(EltTy, 1.0);
     return Builder.CreateFDiv(One, Op0, "hlsl.rcp");
   }
   case Builtin::BI__builtin_hlsl_elementwise_rsqrt: {

mikerice1969 referenced this pull request Jul 15, 2024
Removing the intrinsic because there is no opCodes for rcp in DXIL or
SPIR-V.
Moving means we don't have to re-implement this feature for each
backend.

fixes #87784

Co-authored-by: Farzon Lotfi <[email protected]>
@mikerice1969 mikerice1969 merged commit 9454400 into llvm:main Jul 16, 2024
10 checks passed
@mikerice1969 mikerice1969 deleted the fix_unchecked_dyn_cast branch July 16, 2024 15:05
sayhaan pushed a commit to sayhaan/llvm-project that referenced this pull request Jul 16, 2024
Summary:
BI__builtin_hlsl_elementwise_rcp is only invoked with a FixedVectorType
so use cast to make this clear and satisfy the static verifier.

Test Plan: 

Reviewers: 

Subscribers: 

Tasks: 

Tags: 


Differential Revision: https://phabricator.intern.facebook.com/D59822413
yuxuanchen1997 pushed a commit that referenced this pull request Jul 25, 2024
Summary:
BI__builtin_hlsl_elementwise_rcp is only invoked with a FixedVectorType
so use cast to make this clear and satisfy the static verifier.

Test Plan: 

Reviewers: 

Subscribers: 

Tasks: 

Tags: 


Differential Revision: https://phabricator.intern.facebook.com/D60251454
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.

3 participants