Skip to content

Commit b5b17bf

Browse files
authored
[RISCV] Fix assertion failure in genShXAddAddShift (#88757)
Fix assertion failure in our downstream CI dtcxzyw/llvm-codegen-benchmark#1.
1 parent b2f07a9 commit b5b17bf

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

llvm/lib/Target/RISCV/RISCVInstrInfo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1986,7 +1986,7 @@ genShXAddAddShift(MachineInstr &Root, unsigned AddOpIdx,
19861986
MRI.getUniqueVRegDef(AddMI->getOperand(AddOpIdx).getReg());
19871987

19881988
unsigned InnerShiftAmt = ShiftMI->getOperand(2).getImm();
1989-
assert(InnerShiftAmt > OuterShiftAmt && "Unexpected shift amount");
1989+
assert(InnerShiftAmt >= OuterShiftAmt && "Unexpected shift amount");
19901990

19911991
unsigned InnerOpc;
19921992
switch (InnerShiftAmt - OuterShiftAmt) {

llvm/test/CodeGen/RISCV/rv64zba.ll

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2389,3 +2389,26 @@ define i64 @array_index_sh4_sh3(ptr %p, i64 %idx1, i64 %idx2) {
23892389
%b = load i64, ptr %a, align 8
23902390
ret i64 %b
23912391
}
2392+
2393+
define ptr @test_gep_gep_dont_crash(ptr %p, i64 %a1, i64 %a2) {
2394+
; RV64I-LABEL: test_gep_gep_dont_crash:
2395+
; RV64I: # %bb.0:
2396+
; RV64I-NEXT: srliw a2, a2, 6
2397+
; RV64I-NEXT: slli a2, a2, 3
2398+
; RV64I-NEXT: slli a1, a1, 3
2399+
; RV64I-NEXT: add a0, a0, a1
2400+
; RV64I-NEXT: add a0, a0, a2
2401+
; RV64I-NEXT: ret
2402+
;
2403+
; RV64ZBA-LABEL: test_gep_gep_dont_crash:
2404+
; RV64ZBA: # %bb.0:
2405+
; RV64ZBA-NEXT: srliw a2, a2, 6
2406+
; RV64ZBA-NEXT: add a1, a2, a1
2407+
; RV64ZBA-NEXT: sh3add a0, a1, a0
2408+
; RV64ZBA-NEXT: ret
2409+
%lshr = lshr i64 %a2, 6
2410+
%and = and i64 %lshr, 67108863
2411+
%gep1 = getelementptr i64, ptr %p, i64 %and
2412+
%gep2 = getelementptr i64, ptr %gep1, i64 %a1
2413+
ret ptr %gep2
2414+
}

0 commit comments

Comments
 (0)