Skip to content

Commit 4eaed56

Browse files
committed
Only bail if add RHS isn't constant
1 parent 07e669e commit 4eaed56

File tree

2 files changed

+7
-14
lines changed

2 files changed

+7
-14
lines changed

llvm/lib/Target/RISCV/RISCVISelLowering.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18391,7 +18391,8 @@ bool RISCVTargetLowering::isDesirableToCommuteWithShift(
1839118391
if (Subtarget.hasStdExtZba() && C2->getZExtValue() >= 1 &&
1839218392
C2->getZExtValue() <= 3 && N->hasOneUse() &&
1839318393
N->user_begin()->getOpcode() == ISD::ADD &&
18394-
!isUsedByLdSt(*N->user_begin(), nullptr))
18394+
!isUsedByLdSt(*N->user_begin(), nullptr) &&
18395+
!isa<ConstantSDNode>(N->user_begin()->getOperand(1)))
1839518396
return false;
1839618397

1839718398
if (C1 && C2) {

llvm/test/CodeGen/RISCV/add_sext_shl_constant.ll

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -335,19 +335,11 @@ define i64 @add_shl_moreOneUse_sh4add(i64 %x) {
335335
}
336336

337337
define i64 @add_shl_rhs_constant(i64 %x, i64 %y) {
338-
; NO-ZBA-LABEL: add_shl_rhs_constant:
339-
; NO-ZBA: # %bb.0:
340-
; NO-ZBA-NEXT: add a0, a0, a1
341-
; NO-ZBA-NEXT: slli a0, a0, 3
342-
; NO-ZBA-NEXT: ret
343-
;
344-
; ZBA-LABEL: add_shl_rhs_constant:
345-
; ZBA: # %bb.0:
346-
; ZBA-NEXT: add a0, a0, a1
347-
; ZBA-NEXT: addi a0, a0, 1
348-
; ZBA-NEXT: slli a0, a0, 3
349-
; ZBA-NEXT: addi a0, a0, -8
350-
; ZBA-NEXT: ret
338+
; RV64-LABEL: add_shl_rhs_constant:
339+
; RV64: # %bb.0:
340+
; RV64-NEXT: add a0, a0, a1
341+
; RV64-NEXT: slli a0, a0, 3
342+
; RV64-NEXT: ret
351343
%a = add i64 %x, 1
352344
%b = add i64 %y, %a
353345
%c = shl i64 %b, 3

0 commit comments

Comments
 (0)