Skip to content

Commit 9b93ccb

Browse files
authored
[RISCV] Fix Immediate Check for Xqcibi UGT (#153141)
The check should be about unsigned 16-bit immediates, not signed ones. This is not a bug per-se, as the old codegen was correct for the uint16_max case, it just didn't end up using `qc.e.bgeui`, which we would prefer it did.
1 parent c430e06 commit 9b93ccb

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

llvm/lib/Target/RISCV/RISCVISelLowering.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2523,11 +2523,10 @@ static void translateSetCCForBranch(const SDLoc &DL, SDValue &LHS, SDValue &RHS,
25232523
}
25242524
break;
25252525
case ISD::SETUGT:
2526-
if (Subtarget.hasVendorXqcibi() && C != INT64_MAX && isInt<16>(C + 1) &&
2527-
C != -1) {
2526+
if (Subtarget.hasVendorXqcibi() && C != INT64_MAX && isUInt<16>(C + 1)) {
25282527
// We have a branch immediate instruction for SETUGE but not SETUGT.
25292528
// Convert X > C to X >= C + 1, if (C + 1) is a 16-bit signed immediate.
2530-
RHS = DAG.getSignedConstant(C + 1, DL, RHS.getValueType());
2529+
RHS = DAG.getConstant(C + 1, DL, RHS.getValueType());
25312530
CC = ISD::SETUGE;
25322531
return;
25332532
}

llvm/test/CodeGen/RISCV/xqcibi.ll

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,8 @@ t:
329329
define i32 @bgeuimm16(i32 %a) {
330330
; RV32I-LABEL: bgeuimm16:
331331
; RV32I: # %bb.0:
332-
; RV32I-NEXT: li a1, 99
332+
; RV32I-NEXT: lui a1, 16
333+
; RV32I-NEXT: addi a1, a1, -2
333334
; RV32I-NEXT: bltu a1, a0, .LBB11_2
334335
; RV32I-NEXT: # %bb.1: # %f
335336
; RV32I-NEXT: li a0, 0
@@ -340,14 +341,14 @@ define i32 @bgeuimm16(i32 %a) {
340341
;
341342
; RV32IXQCIBI-LABEL: bgeuimm16:
342343
; RV32IXQCIBI: # %bb.0:
343-
; RV32IXQCIBI-NEXT: qc.e.bgeui a0, 100, .LBB11_2
344+
; RV32IXQCIBI-NEXT: qc.e.bgeui a0, 65535, .LBB11_2
344345
; RV32IXQCIBI-NEXT: # %bb.1: # %f
345346
; RV32IXQCIBI-NEXT: li a0, 0
346347
; RV32IXQCIBI-NEXT: ret
347348
; RV32IXQCIBI-NEXT: .LBB11_2: # %t
348349
; RV32IXQCIBI-NEXT: li a0, 1
349350
; RV32IXQCIBI-NEXT: ret
350-
%1 = icmp uge i32 %a, 100
351+
%1 = icmp uge i32 %a, 65535
351352
br i1 %1, label %t, label %f, !prof !0
352353
f:
353354
ret i32 0

0 commit comments

Comments
 (0)