Skip to content

Commit

Permalink
[RISCV] Override TargetLowering::hasAndNot for Zbb.
Browse files Browse the repository at this point in the history
Differential Revision: https://reviews.llvm.org/D113937
  • Loading branch information
topperc committed Nov 16, 2021
1 parent d90eeab commit 391b0ba
Show file tree
Hide file tree
Showing 4 changed files with 675 additions and 166 deletions.
10 changes: 10 additions & 0 deletions llvm/lib/Target/RISCV/RISCVISelLowering.cpp
Expand Up @@ -1105,6 +1105,16 @@ bool RISCVTargetLowering::isCheapToSpeculateCtlz() const {
return Subtarget.hasStdExtZbb();
}

bool RISCVTargetLowering::hasAndNot(SDValue Y) const {
EVT VT = Y.getValueType();

// FIXME: Support vectors once we have tests.
if (VT.isVector())
return false;

return Subtarget.hasStdExtZbb() && !isa<ConstantSDNode>(Y);
}

/// Check if sinking \p I's operands to I's basic block is profitable, because
/// the operands can be folded into a target instruction, e.g.
/// splats of scalars can fold into vector instructions.
Expand Down
1 change: 1 addition & 0 deletions llvm/lib/Target/RISCV/RISCVISelLowering.h
Expand Up @@ -315,6 +315,7 @@ class RISCVTargetLowering : public TargetLowering {
bool isSExtCheaperThanZExt(EVT SrcVT, EVT DstVT) const override;
bool isCheapToSpeculateCttz() const override;
bool isCheapToSpeculateCtlz() const override;
bool hasAndNot(SDValue Y) const override;
bool shouldSinkOperands(Instruction *I,
SmallVectorImpl<Use *> &Ops) const override;
bool isFPImmLegal(const APFloat &Imm, EVT VT,
Expand Down
37 changes: 29 additions & 8 deletions llvm/test/CodeGen/RISCV/selectcc-to-shiftand.ll
Expand Up @@ -117,14 +117,35 @@ define i32 @pos_sel_special_constant(i32 signext %a) {

; Compare if positive and select variable or zero.
define i32 @pos_sel_variable_and_zero(i32 signext %a, i32 signext %b) {
; CHECK-LABEL: pos_sel_variable_and_zero:
; CHECK: # %bb.0:
; CHECK-NEXT: bgez a0, .LBB6_2
; CHECK-NEXT: # %bb.1:
; CHECK-NEXT: mv a1, zero
; CHECK-NEXT: .LBB6_2:
; CHECK-NEXT: mv a0, a1
; CHECK-NEXT: ret
; RV32I-LABEL: pos_sel_variable_and_zero:
; RV32I: # %bb.0:
; RV32I-NEXT: bgez a0, .LBB6_2
; RV32I-NEXT: # %bb.1:
; RV32I-NEXT: mv a1, zero
; RV32I-NEXT: .LBB6_2:
; RV32I-NEXT: mv a0, a1
; RV32I-NEXT: ret
;
; RV64I-LABEL: pos_sel_variable_and_zero:
; RV64I: # %bb.0:
; RV64I-NEXT: bgez a0, .LBB6_2
; RV64I-NEXT: # %bb.1:
; RV64I-NEXT: mv a1, zero
; RV64I-NEXT: .LBB6_2:
; RV64I-NEXT: mv a0, a1
; RV64I-NEXT: ret
;
; RV32ZBB-LABEL: pos_sel_variable_and_zero:
; RV32ZBB: # %bb.0:
; RV32ZBB-NEXT: srai a0, a0, 31
; RV32ZBB-NEXT: andn a0, a1, a0
; RV32ZBB-NEXT: ret
;
; RV64ZBB-LABEL: pos_sel_variable_and_zero:
; RV64ZBB: # %bb.0:
; RV64ZBB-NEXT: srai a0, a0, 31
; RV64ZBB-NEXT: andn a0, a1, a0
; RV64ZBB-NEXT: ret
%tmp.1 = icmp sgt i32 %a, -1
%retval = select i1 %tmp.1, i32 %b, i32 0
ret i32 %retval
Expand Down

0 comments on commit 391b0ba

Please sign in to comment.