Skip to content

Commit faab8f7

Browse files
authored
[RISCV] Add th.ext(u) to RISCVDAGToDAGISel::hasAllNBitUsers. (llvm#157133)
These instructions are being used by the scalar efficiency SIG to determine if we should have a standard instruction. Improving our support for these instructions may give better data for their analysis. I'll follow up by adding this to RISCVOptWInstrs too which will remove the 'w' suffixes added here.
1 parent 5cf4959 commit faab8f7

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3937,6 +3937,15 @@ bool RISCVDAGToDAGISel::hasAllNBitUsers(SDNode *Node, unsigned Bits,
39373937
if (Use.getOperandNo() == 0 && Bits >= 32)
39383938
break;
39393939
return false;
3940+
case RISCV::TH_EXT:
3941+
case RISCV::TH_EXTU: {
3942+
unsigned Msb = User->getConstantOperandVal(1);
3943+
unsigned Lsb = User->getConstantOperandVal(2);
3944+
// Behavior of Msb < Lsb is not well documented.
3945+
if (Msb >= Lsb && Bits > Msb)
3946+
break;
3947+
return false;
3948+
}
39403949
}
39413950
}
39423951

llvm/test/CodeGen/RISCV/bitextract-mac.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ define i32 @f(i32 %A, i32 %B, i32 %C) {
107107
;
108108
; RV64XTHEADBB-LABEL: f:
109109
; RV64XTHEADBB: # %bb.0: # %entry
110-
; RV64XTHEADBB-NEXT: mul a0, a1, a0
110+
; RV64XTHEADBB-NEXT: mulw a0, a1, a0
111111
; RV64XTHEADBB-NEXT: th.extu a1, a0, 5, 2
112112
; RV64XTHEADBB-NEXT: th.extu a0, a0, 11, 5
113113
; RV64XTHEADBB-NEXT: mul a0, a1, a0
@@ -116,7 +116,7 @@ define i32 @f(i32 %A, i32 %B, i32 %C) {
116116
;
117117
; RV64XTHEAD-LABEL: f:
118118
; RV64XTHEAD: # %bb.0: # %entry
119-
; RV64XTHEAD-NEXT: mul a0, a1, a0
119+
; RV64XTHEAD-NEXT: mulw a0, a1, a0
120120
; RV64XTHEAD-NEXT: th.extu a1, a0, 5, 2
121121
; RV64XTHEAD-NEXT: th.extu a0, a0, 11, 5
122122
; RV64XTHEAD-NEXT: th.mulah a2, a1, a0

llvm/test/CodeGen/RISCV/ctlz-cttz-ctpop.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2438,7 +2438,7 @@ define i16 @test_ctpop_i16(i16 %a) nounwind {
24382438
; RV64XTHEADBB-NEXT: and a0, a0, a2
24392439
; RV64XTHEADBB-NEXT: add a0, a1, a0
24402440
; RV64XTHEADBB-NEXT: srli a1, a0, 4
2441-
; RV64XTHEADBB-NEXT: add a0, a0, a1
2441+
; RV64XTHEADBB-NEXT: addw a0, a0, a1
24422442
; RV64XTHEADBB-NEXT: th.extu a1, a0, 11, 8
24432443
; RV64XTHEADBB-NEXT: andi a0, a0, 15
24442444
; RV64XTHEADBB-NEXT: add a0, a0, a1

0 commit comments

Comments
 (0)