[clang] [llvm] [HLSL] Re-implement countbits with the correct return type (PR #113189)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Oct 21 09:25:38 PDT 2024
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 d9c95efb6c102fc9e9c52a558d611bb7aa433dbb f110f3167769d91dd87b260b30c2a61cc754b619 --extensions h,cpp -- clang/lib/Headers/hlsl/hlsl_intrinsics.h llvm/lib/Target/DirectX/DXILOpLowering.cpp
``````````
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/clang/lib/Headers/hlsl/hlsl_intrinsics.h b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
index 2a612c3746..dbb55b5ecd 100644
--- a/clang/lib/Headers/hlsl/hlsl_intrinsics.h
+++ b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
@@ -738,31 +738,15 @@ constexpr uint4 countbits(uint16_t4 x) {
}
#endif
-constexpr uint countbits(int x) {
- return __builtin_elementwise_popcount(x);
-}
-constexpr uint2 countbits(int2 x) {
- return __builtin_elementwise_popcount(x);
-}
-constexpr uint3 countbits(int3 x) {
- return __builtin_elementwise_popcount(x);
-}
-constexpr uint4 countbits(int4 x) {
- return __builtin_elementwise_popcount(x);
-}
-
-constexpr uint countbits(uint x) {
- return __builtin_elementwise_popcount(x);
-}
-constexpr uint2 countbits(uint2 x) {
- return __builtin_elementwise_popcount(x);
-}
-constexpr uint3 countbits(uint3 x) {
- return __builtin_elementwise_popcount(x);
-}
-constexpr uint4 countbits(uint4 x) {
- return __builtin_elementwise_popcount(x);
-}
+constexpr uint countbits(int x) { return __builtin_elementwise_popcount(x); }
+constexpr uint2 countbits(int2 x) { return __builtin_elementwise_popcount(x); }
+constexpr uint3 countbits(int3 x) { return __builtin_elementwise_popcount(x); }
+constexpr uint4 countbits(int4 x) { return __builtin_elementwise_popcount(x); }
+
+constexpr uint countbits(uint x) { return __builtin_elementwise_popcount(x); }
+constexpr uint2 countbits(uint2 x) { return __builtin_elementwise_popcount(x); }
+constexpr uint3 countbits(uint3 x) { return __builtin_elementwise_popcount(x); }
+constexpr uint4 countbits(uint4 x) { return __builtin_elementwise_popcount(x); }
constexpr uint countbits(int64_t x) {
return __builtin_elementwise_popcount(x);
diff --git a/llvm/lib/Target/DirectX/DXILOpLowering.cpp b/llvm/lib/Target/DirectX/DXILOpLowering.cpp
index a0b5df2576..344605fa3c 100644
--- a/llvm/lib/Target/DirectX/DXILOpLowering.cpp
+++ b/llvm/lib/Target/DirectX/DXILOpLowering.cpp
@@ -464,7 +464,7 @@ public:
[[nodiscard]] bool lowerCtpopToCBits(Function &F) {
IRBuilder<> &IRB = OpBuilder.getIRB();
Type *Int32Ty = IRB.getInt32Ty();
-
+
return replaceFunction(F, [&](CallInst *CI) -> Error {
IRB.SetInsertPoint(CI);
SmallVector<Value *> Args;
@@ -474,26 +474,26 @@ public:
Type *FRT = F.getReturnType();
if (FRT->isVectorTy()) {
VectorType *VT = cast<VectorType>(FRT);
- RetTy = VectorType::get(RetTy, VT);
+ RetTy = VectorType::get(RetTy, VT);
}
-
- Expected<CallInst *> OpCall =
- OpBuilder.tryCreateOp(dxil::OpCode::CBits, Args, CI->getName(), RetTy);
+
+ Expected<CallInst *> OpCall = OpBuilder.tryCreateOp(
+ dxil::OpCode::CBits, Args, CI->getName(), RetTy);
if (Error E = OpCall.takeError())
- return E;
+ return E;
// If the result type is 32 bits we can do a direct replacement.
if (FRT->isIntOrIntVectorTy(32)) {
CI->replaceAllUsesWith(*OpCall);
- CI->eraseFromParent();
- return Error::success();
+ CI->eraseFromParent();
+ return Error::success();
}
unsigned CastOp;
if (FRT->isIntOrIntVectorTy(16))
- CastOp = Instruction::ZExt;
+ CastOp = Instruction::ZExt;
else // must be 64 bits
- CastOp = Instruction::Trunc;
+ CastOp = Instruction::Trunc;
// It is correct to replace the ctpop with the dxil op and
// remove an existing cast iff the cast is the only usage of
@@ -501,21 +501,21 @@ public:
// can use hasOneUse instead of hasOneUser, because the user
// we care about should have one operand
if (CI->hasOneUse()) {
- User *U = CI->user_back();
- Instruction *I;
- if (isa<Instruction>(U) && (I = cast<Instruction>(U)) &&
- I->getOpcode() == CastOp && I->getType() == RetTy) {
+ User *U = CI->user_back();
+ Instruction *I;
+ if (isa<Instruction>(U) && (I = cast<Instruction>(U)) &&
+ I->getOpcode() == CastOp && I->getType() == RetTy) {
I->replaceAllUsesWith(*OpCall);
- I->eraseFromParent();
- CI->eraseFromParent();
- return Error::success();
- }
+ I->eraseFromParent();
+ CI->eraseFromParent();
+ return Error::success();
+ }
}
// It is always correct to replace a ctpop with the dxil op and
// a cast
- Value *Cast = IRB.CreateZExtOrTrunc(*OpCall, F.getReturnType(),
- "ctpop.cast");
+ Value *Cast =
+ IRB.CreateZExtOrTrunc(*OpCall, F.getReturnType(), "ctpop.cast");
CI->replaceAllUsesWith(Cast);
CI->eraseFromParent();
return Error::success();
@@ -551,8 +551,8 @@ public:
HasErrors |= lowerTypedBufferStore(F);
break;
case Intrinsic::ctpop:
- HasErrors |= lowerCtpopToCBits(F);
- break;
+ HasErrors |= lowerCtpopToCBits(F);
+ break;
}
Updated = true;
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/113189
More information about the cfe-commits
mailing list