[clang] [llvm] [DirectX] Add isinf f16 emulation for SM6.8 and lower (PR #156932)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 4 10:23:47 PDT 2025
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {clang-format}-->
:warning: C/C++ code formatter, clang-format found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
git-clang-format --diff origin/main HEAD --extensions cpp,h -- clang/lib/Driver/ToolChains/HLSL.cpp llvm/include/llvm/TargetParser/Triple.h llvm/lib/Target/DirectX/DXILIntrinsicExpansion.cpp llvm/lib/TargetParser/Triple.cpp llvm/unittests/TargetParser/TripleTest.cpp
``````````
:warning:
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing `origin/main` to the base branch/commit you want to compare against.
:warning:
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/llvm/lib/Target/DirectX/DXILIntrinsicExpansion.cpp b/llvm/lib/Target/DirectX/DXILIntrinsicExpansion.cpp
index 7966e3f1d..06aade7d0 100644
--- a/llvm/lib/Target/DirectX/DXILIntrinsicExpansion.cpp
+++ b/llvm/lib/Target/DirectX/DXILIntrinsicExpansion.cpp
@@ -51,41 +51,42 @@ static bool resourceAccessNeeds64BitExpansion(Module *M, Type *OverloadTy,
return ScalarTy->isDoubleTy() || ScalarTy->isIntegerTy(64);
}
- static Value* expand16BitIsInf(CallInst *Orig) {
- Module* M = Orig->getModule();
- if(M->getTargetTriple().getDXILVersion() >= VersionTuple(1, 9))
- return nullptr;
-
- Value *Val = Orig->getOperand(0);
- Type* ValTy = Val->getType();
- if (!(ValTy->isHalfTy() ||
- (ValTy->isVectorTy() &&
- cast<FixedVectorType>(ValTy)->getElementType()->isHalfTy())))
- return nullptr;
-
- IRBuilder<> Builder(Orig);
- Type *IType = Type::getInt16Ty(M->getContext());
- Constant *PosInf = ValTy->isVectorTy()
- ? ConstantVector::getSplat(
- ElementCount::getFixed(
- cast<FixedVectorType>(ValTy)->getNumElements()),
- ConstantInt::get(IType, 0x7c00))
- : ConstantInt::get(IType, 0x7c00);
-
- Constant *NegInf = ValTy->isVectorTy()
- ? ConstantVector::getSplat(
- ElementCount::getFixed(
- cast<FixedVectorType>(ValTy)->getNumElements()),
- ConstantInt::get(IType, 0xfc00))
- : ConstantInt::get(IType, 0xfc00);
+static Value *expand16BitIsInf(CallInst *Orig) {
+ Module *M = Orig->getModule();
+ if (M->getTargetTriple().getDXILVersion() >= VersionTuple(1, 9))
+ return nullptr;
+ Value *Val = Orig->getOperand(0);
+ Type *ValTy = Val->getType();
+ if (!(ValTy->isHalfTy() ||
+ (ValTy->isVectorTy() &&
+ cast<FixedVectorType>(ValTy)->getElementType()->isHalfTy())))
+ return nullptr;
- Value *IVal = Builder.CreateBitCast(Val, PosInf->getType());
- Value *B1 = Builder.CreateICmpEQ(IVal, PosInf);
- Value *B2 = Builder.CreateICmpEQ(IVal, NegInf);
- Value *B3 = Builder.CreateOr(B1, B2);
- return B3;
- }
+ IRBuilder<> Builder(Orig);
+ Type *IType = Type::getInt16Ty(M->getContext());
+ Constant *PosInf =
+ ValTy->isVectorTy()
+ ? ConstantVector::getSplat(
+ ElementCount::getFixed(
+ cast<FixedVectorType>(ValTy)->getNumElements()),
+ ConstantInt::get(IType, 0x7c00))
+ : ConstantInt::get(IType, 0x7c00);
+
+ Constant *NegInf =
+ ValTy->isVectorTy()
+ ? ConstantVector::getSplat(
+ ElementCount::getFixed(
+ cast<FixedVectorType>(ValTy)->getNumElements()),
+ ConstantInt::get(IType, 0xfc00))
+ : ConstantInt::get(IType, 0xfc00);
+
+ Value *IVal = Builder.CreateBitCast(Val, PosInf->getType());
+ Value *B1 = Builder.CreateICmpEQ(IVal, PosInf);
+ Value *B2 = Builder.CreateICmpEQ(IVal, NegInf);
+ Value *B3 = Builder.CreateOr(B1, B2);
+ return B3;
+}
static bool isIntrinsicExpansion(Function &F) {
switch (F.getIntrinsicID()) {
diff --git a/llvm/lib/TargetParser/Triple.cpp b/llvm/lib/TargetParser/Triple.cpp
index 2ee27ba4a..71517e5e9 100644
--- a/llvm/lib/TargetParser/Triple.cpp
+++ b/llvm/lib/TargetParser/Triple.cpp
@@ -652,7 +652,7 @@ static Triple::ArchType parseArch(StringRef ArchName) {
.Cases("dxil", "dxilv1.0", "dxilv1.1", "dxilv1.2", "dxilv1.3",
"dxilv1.4", "dxilv1.5", "dxilv1.6", "dxilv1.7",
"dxilv1.8", Triple::dxil)
- //Note: Cases has max limit of 10.
+ // Note: Cases has max limit of 10.
.Case("dxilv1.9", Triple::dxil)
.Case("xtensa", Triple::xtensa)
.Default(Triple::UnknownArch);
``````````
</details>
https://github.com/llvm/llvm-project/pull/156932
More information about the llvm-commits
mailing list