Skip to content

Commit 679cc16

Browse files
committed
[RISCV] Disable early promotion for Zbs in performANDCombine with riscv-experimental-rv64-legal-i32
We can match this directly in isel with the i32 type being legal. The generic DAG combine will unpromote part of the pattern and prevent it from being matched in isel.
1 parent 5e245ab commit 679cc16

File tree

2 files changed

+3
-5
lines changed

2 files changed

+3
-5
lines changed

llvm/lib/Target/RISCV/RISCVISelLowering.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12269,7 +12269,7 @@ static SDValue performANDCombine(SDNode *N,
1226912269
// shift amounts larger than 31 would produce poison. If we wait until
1227012270
// type legalization, we'll create RISCVISD::SRLW and we can't recover it
1227112271
// to use a BEXT instruction.
12272-
if (Subtarget.is64Bit() && Subtarget.hasStdExtZbs() &&
12272+
if (!RV64LegalI32 && Subtarget.is64Bit() && Subtarget.hasStdExtZbs() &&
1227312273
N->getValueType(0) == MVT::i32 && isOneConstant(N->getOperand(1)) &&
1227412274
N0.getOpcode() == ISD::SRL && !isa<ConstantSDNode>(N0.getOperand(1)) &&
1227512275
N0.hasOneUse()) {

llvm/test/CodeGen/RISCV/rv64-legal-i32/rv64zbs.ll

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -333,8 +333,7 @@ define signext i32 @bext_i32(i32 signext %a, i32 signext %b) nounwind {
333333
; RV64ZBS-LABEL: bext_i32:
334334
; RV64ZBS: # %bb.0:
335335
; RV64ZBS-NEXT: andi a1, a1, 31
336-
; RV64ZBS-NEXT: srl a0, a0, a1
337-
; RV64ZBS-NEXT: andi a0, a0, 1
336+
; RV64ZBS-NEXT: bext a0, a0, a1
338337
; RV64ZBS-NEXT: ret
339338
%and = and i32 %b, 31
340339
%shr = lshr i32 %a, %and
@@ -351,8 +350,7 @@ define signext i32 @bext_i32_no_mask(i32 signext %a, i32 signext %b) nounwind {
351350
;
352351
; RV64ZBS-LABEL: bext_i32_no_mask:
353352
; RV64ZBS: # %bb.0:
354-
; RV64ZBS-NEXT: srl a0, a0, a1
355-
; RV64ZBS-NEXT: andi a0, a0, 1
353+
; RV64ZBS-NEXT: bext a0, a0, a1
356354
; RV64ZBS-NEXT: ret
357355
%shr = lshr i32 %a, %b
358356
%and1 = and i32 %shr, 1

0 commit comments

Comments
 (0)