Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1131e44

Browse files
authored
[RISCV] Use hasCPOPLike in isCtpopFast and getPopcntSupport (llvm#158371)
1 parent 13eecf7 commit 1131e44

File tree

3 files changed

+49
-5
lines changed

3 files changed

+49
-5
lines changed

llvm/lib/Target/RISCV/RISCVISelLowering.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24844,8 +24844,7 @@ bool RISCVTargetLowering::isCtpopFast(EVT VT) const {
2484424844
return isTypeLegal(VT) && Subtarget.hasStdExtZvbb();
2484524845
if (VT.isFixedLengthVector() && Subtarget.hasStdExtZvbb())
2484624846
return true;
24847-
// FIXME: Should use hasCPOPLike here.
24848-
return Subtarget.hasStdExtZbb() &&
24847+
return Subtarget.hasCPOPLike() &&
2484924848
(VT == MVT::i32 || VT == MVT::i64 || VT.isFixedLengthVector());
2485024849
}
2485124850

llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -289,9 +289,7 @@ bool RISCVTTIImpl::hasActiveVectorLength() const {
289289
TargetTransformInfo::PopcntSupportKind
290290
RISCVTTIImpl::getPopcntSupport(unsigned TyWidth) const {
291291
assert(isPowerOf2_32(TyWidth) && "Ty width must be power of 2");
292-
return ST->hasStdExtZbb() || (ST->hasVendorXCVbitmanip() && !ST->is64Bit())
293-
? TTI::PSK_FastHardware
294-
: TTI::PSK_Software;
292+
return ST->hasCPOPLike() ? TTI::PSK_FastHardware : TTI::PSK_Software;
295293
}
296294

297295
InstructionCost RISCVTTIImpl::getPartialReductionCost(

llvm/test/CodeGen/RISCV/xcvbitmanip.ll

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,3 +229,50 @@ define i32 @test.llvm.bitrev(i32 %a) {
229229
%1 = call i32 @llvm.bitreverse(i32 %a)
230230
ret i32 %1
231231
}
232+
233+
define i1 @ctpop_i32_ult_two(i32 signext %a) nounwind {
234+
; CHECK-LABEL: ctpop_i32_ult_two:
235+
; CHECK: # %bb.0:
236+
; CHECK-NEXT: cv.cnt a0, a0
237+
; CHECK-NEXT: sltiu a0, a0, 2
238+
; CHECK-NEXT: ret
239+
%1 = call i32 @llvm.ctpop.i32(i32 %a)
240+
%2 = icmp ult i32 %1, 2
241+
ret i1 %2
242+
}
243+
244+
define i1 @ctpop_i32_ugt_one(i32 signext %a) nounwind {
245+
; CHECK-LABEL: ctpop_i32_ugt_one:
246+
; CHECK: # %bb.0:
247+
; CHECK-NEXT: cv.cnt a0, a0
248+
; CHECK-NEXT: sltiu a0, a0, 2
249+
; CHECK-NEXT: xori a0, a0, 1
250+
; CHECK-NEXT: ret
251+
%1 = call i32 @llvm.ctpop.i32(i32 %a)
252+
%2 = icmp ugt i32 %1, 1
253+
ret i1 %2
254+
}
255+
256+
define i1 @ctpop_i32_eq_one(i32 signext %a) nounwind {
257+
; CHECK-LABEL: ctpop_i32_eq_one:
258+
; CHECK: # %bb.0:
259+
; CHECK-NEXT: cv.cnt a0, a0
260+
; CHECK-NEXT: addi a0, a0, -1
261+
; CHECK-NEXT: seqz a0, a0
262+
; CHECK-NEXT: ret
263+
%1 = call i32 @llvm.ctpop.i32(i32 %a)
264+
%2 = icmp eq i32 %1, 1
265+
ret i1 %2
266+
}
267+
268+
define i1 @ctpop_i32_ne_one(i32 signext %a) nounwind {
269+
; CHECK-LABEL: ctpop_i32_ne_one:
270+
; CHECK: # %bb.0:
271+
; CHECK-NEXT: cv.cnt a0, a0
272+
; CHECK-NEXT: addi a0, a0, -1
273+
; CHECK-NEXT: snez a0, a0
274+
; CHECK-NEXT: ret
275+
%1 = call i32 @llvm.ctpop.i32(i32 %a)
276+
%2 = icmp ne i32 %1, 1
277+
ret i1 %2
278+
}

0 commit comments

Comments
 (0)