[llvm] af05f9f - [AMDGPU] - Add constant folding for s_bitreplicate (#72366)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Nov 16 00:08:04 PST 2023
Author: Jessica Del
Date: 2023-11-16T09:08:00+01:00
New Revision: af05f9ff06a20b9f58fdb4e9e6e1db5bee1abcf5
URL: https://github.com/llvm/llvm-project/commit/af05f9ff06a20b9f58fdb4e9e6e1db5bee1abcf5
DIFF: https://github.com/llvm/llvm-project/commit/af05f9ff06a20b9f58fdb4e9e6e1db5bee1abcf5.diff
LOG: [AMDGPU] - Add constant folding for s_bitreplicate (#72366)
If the input is a constant, we can constant fold the s_bitreplicate
operation.
Added:
Modified:
llvm/lib/Analysis/ConstantFolding.cpp
llvm/test/CodeGen/AMDGPU/llvm.amdgcn.bitreplicate.ll
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/ConstantFolding.cpp b/llvm/lib/Analysis/ConstantFolding.cpp
index 966a65ac26b8017..5b385e9df24183f 100644
--- a/llvm/lib/Analysis/ConstantFolding.cpp
+++ b/llvm/lib/Analysis/ConstantFolding.cpp
@@ -1533,6 +1533,7 @@ bool llvm::canConstantFoldCallTo(const CallBase *Call, const Function *F) {
case Intrinsic::amdgcn_perm:
case Intrinsic::amdgcn_wave_reduce_umin:
case Intrinsic::amdgcn_wave_reduce_umax:
+ case Intrinsic::amdgcn_s_bitreplicate:
case Intrinsic::arm_mve_vctp8:
case Intrinsic::arm_mve_vctp16:
case Intrinsic::arm_mve_vctp32:
@@ -2422,6 +2423,18 @@ static Constant *ConstantFoldScalarCall1(StringRef Name,
return ConstantFP::get(Ty->getContext(), Val);
}
+
+ case Intrinsic::amdgcn_s_bitreplicate: {
+ uint64_t Val = Op->getZExtValue();
+ Val = (Val & 0x000000000000FFFFULL) | (Val & 0x00000000FFFF0000ULL) << 16;
+ Val = (Val & 0x000000FF000000FFULL) | (Val & 0x0000FF000000FF00ULL) << 8;
+ Val = (Val & 0x000F000F000F000FULL) | (Val & 0x00F000F000F000F0ULL) << 4;
+ Val = (Val & 0x0303030303030303ULL) | (Val & 0x0C0C0C0C0C0C0C0CULL) << 2;
+ Val = (Val & 0x1111111111111111ULL) | (Val & 0x2222222222222222ULL) << 1;
+ Val = Val | Val << 1;
+ return ConstantInt::get(Ty, Val);
+ }
+
default:
return nullptr;
}
diff --git a/llvm/test/CodeGen/AMDGPU/llvm.amdgcn.bitreplicate.ll b/llvm/test/CodeGen/AMDGPU/llvm.amdgcn.bitreplicate.ll
index 027c9ef5e7cc349..0937280e6352c80 100644
--- a/llvm/test/CodeGen/AMDGPU/llvm.amdgcn.bitreplicate.ll
+++ b/llvm/test/CodeGen/AMDGPU/llvm.amdgcn.bitreplicate.ll
@@ -8,8 +8,8 @@ define i64 @test_s_bitreplicate_constant() {
; GFX11-LABEL: test_s_bitreplicate_constant:
; GFX11: ; %bb.0: ; %entry
; GFX11-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
-; GFX11-NEXT: s_bitreplicate_b64_b32 s[0:1], 0x85fe3a92
-; GFX11-NEXT: v_dual_mov_b32 v0, s0 :: v_dual_mov_b32 v1, s1
+; GFX11-NEXT: v_mov_b32_e32 v0, 0xfccc30c
+; GFX11-NEXT: v_mov_b32_e32 v1, 0xc033fffc
; GFX11-NEXT: s_setpc_b64 s[30:31]
entry:
%br = call i64 @llvm.amdgcn.s.bitreplicate(i32 u0x85FE3A92)
More information about the llvm-commits
mailing list