Skip to content

Commit

Permalink
[RISCV] Add SimplifyDemandedBits support for FSR/FSL/FSRW/FSLW.
Browse files Browse the repository at this point in the history
  • Loading branch information
topperc committed Mar 6, 2022
1 parent 2d0c9b6 commit bd5f124
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 0 deletions.
15 changes: 15 additions & 0 deletions llvm/lib/Target/RISCV/RISCVISelLowering.cpp
Expand Up @@ -8207,6 +8207,21 @@ SDValue RISCVTargetLowering::PerformDAGCombine(SDNode *N,

break;
}
case RISCVISD::FSR:
case RISCVISD::FSL:
case RISCVISD::FSRW:
case RISCVISD::FSLW: {
bool IsWInstruction =
N->getOpcode() == RISCVISD::FSRW || N->getOpcode() == RISCVISD::FSLW;
unsigned BitWidth =
IsWInstruction ? 32 : N->getSimpleValueType(0).getSizeInBits();
assert(isPowerOf2_32(BitWidth) && "Unexpected bit width");
// Only the lower log2(Bitwidth)+1 bits of the the shift amount are read.
if (SimplifyDemandedLowBitsHelper(1, Log2_32(BitWidth) + 1))
return SDValue(N, 0);

break;
}
case RISCVISD::FMV_X_ANYEXTH:
case RISCVISD::FMV_X_ANYEXTW_RV64: {
SDLoc DL(N);
Expand Down
22 changes: 22 additions & 0 deletions llvm/test/CodeGen/RISCV/rv32zbt-intrinsic.ll
Expand Up @@ -13,6 +13,17 @@ define i32 @fsl_i32(i32 %a, i32 %b, i32 %c) nounwind {
ret i32 %1
}

define i32 @fsl_i32_demandedbits(i32 %a, i32 %b, i32 %c) nounwind {
; RV32ZBT-LABEL: fsl_i32_demandedbits:
; RV32ZBT: # %bb.0:
; RV32ZBT-NEXT: andi a1, a1, 31
; RV32ZBT-NEXT: fsl a0, a0, a1, a2
; RV32ZBT-NEXT: ret
%bmask = and i32 %b, 95
%1 = call i32 @llvm.riscv.fsl.i32(i32 %a, i32 %bmask, i32 %c)
ret i32 %1
}

declare i32 @llvm.riscv.fsr.i32(i32, i32, i32)

define i32 @fsr_i32(i32 %a, i32 %b, i32 %c) nounwind {
Expand All @@ -24,6 +35,17 @@ define i32 @fsr_i32(i32 %a, i32 %b, i32 %c) nounwind {
ret i32 %1
}

define i32 @fsr_i32_demandedbits(i32 %a, i32 %b, i32 %c) nounwind {
; RV32ZBT-LABEL: fsr_i32_demandedbits:
; RV32ZBT: # %bb.0:
; RV32ZBT-NEXT: andi a1, a1, 31
; RV32ZBT-NEXT: fsr a0, a0, a1, a2
; RV32ZBT-NEXT: ret
%bmask = and i32 %b, 95
%1 = call i32 @llvm.riscv.fsr.i32(i32 %a, i32 %bmask, i32 %c)
ret i32 %1
}

define i32 @fsli_i32(i32 %a, i32 %b) nounwind {
; RV32ZBT-LABEL: fsli_i32:
; RV32ZBT: # %bb.0:
Expand Down
44 changes: 44 additions & 0 deletions llvm/test/CodeGen/RISCV/rv64zbt-intrinsic.ll
Expand Up @@ -13,6 +13,17 @@ define i32 @fsl_i32(i32 %a, i32 %b, i32 %c) nounwind {
ret i32 %1
}

define i32 @fsl_i32_demandedbits(i32 %a, i32 %b, i32 %c) nounwind {
; RV64ZBT-LABEL: fsl_i32_demandedbits:
; RV64ZBT: # %bb.0:
; RV64ZBT-NEXT: andi a1, a1, 31
; RV64ZBT-NEXT: fslw a0, a0, a1, a2
; RV64ZBT-NEXT: ret
%bmask = and i32 %b, 95
%1 = call i32 @llvm.riscv.fsl.i32(i32 %a, i32 %bmask, i32 %c)
ret i32 %1
}

declare i32 @llvm.riscv.fsr.i32(i32, i32, i32)

define i32 @fsr_i32(i32 %a, i32 %b, i32 %c) nounwind {
Expand All @@ -24,6 +35,17 @@ define i32 @fsr_i32(i32 %a, i32 %b, i32 %c) nounwind {
ret i32 %1
}

define i32 @fsr_i32_demandedbits(i32 %a, i32 %b, i32 %c) nounwind {
; RV64ZBT-LABEL: fsr_i32_demandedbits:
; RV64ZBT: # %bb.0:
; RV64ZBT-NEXT: andi a1, a1, 31
; RV64ZBT-NEXT: fsrw a0, a0, a1, a2
; RV64ZBT-NEXT: ret
%bmask = and i32 %b, 95
%1 = call i32 @llvm.riscv.fsr.i32(i32 %a, i32 %bmask, i32 %c)
ret i32 %1
}

define i32 @fsli_i32(i32 %a, i32 %b) nounwind {
; RV64ZBT-LABEL: fsli_i32:
; RV64ZBT: # %bb.0:
Expand Down Expand Up @@ -53,6 +75,17 @@ define i64 @fsl_i64(i64 %a, i64 %b, i64 %c) nounwind {
ret i64 %1
}

define i64 @fsl_i64_demandedbits(i64 %a, i64 %b, i64 %c) nounwind {
; RV64ZBT-LABEL: fsl_i64_demandedbits:
; RV64ZBT: # %bb.0:
; RV64ZBT-NEXT: andi a1, a1, 63
; RV64ZBT-NEXT: fsl a0, a0, a1, a2
; RV64ZBT-NEXT: ret
%bmask = and i64 %b, 191
%1 = call i64 @llvm.riscv.fsl.i64(i64 %a, i64 %bmask, i64 %c)
ret i64 %1
}

declare i64 @llvm.riscv.fsr.i64(i64, i64, i64)

define i64 @fsr_i64(i64 %a, i64 %b, i64 %c) nounwind {
Expand All @@ -64,6 +97,17 @@ define i64 @fsr_i64(i64 %a, i64 %b, i64 %c) nounwind {
ret i64 %1
}

define i64 @fsr_i64_demandedbits(i64 %a, i64 %b, i64 %c) nounwind {
; RV64ZBT-LABEL: fsr_i64_demandedbits:
; RV64ZBT: # %bb.0:
; RV64ZBT-NEXT: andi a1, a1, 63
; RV64ZBT-NEXT: fsr a0, a0, a1, a2
; RV64ZBT-NEXT: ret
%bmask = and i64 %b, 191
%1 = call i64 @llvm.riscv.fsr.i64(i64 %a, i64 %bmask, i64 %c)
ret i64 %1
}

define i64 @fsli_i64(i64 %a, i64 %b) nounwind {
; RV64ZBT-LABEL: fsli_i64:
; RV64ZBT: # %bb.0:
Expand Down

0 comments on commit bd5f124

Please sign in to comment.