Skip to content

Commit 1b49bbc

Browse files
vladimirradosavljevicakiramenai
authored andcommitted
[EraVM] Fix EraVMCombineAddressingMode::mergeSelect for SEL with stack as output
This patch fixes the issue in mergeSelect where Base is SEL with stack as output and that output operand is not copied to the newly created SEL. This happens when we are replacing second operand of SEL (IsIn0 is false) with In, and we are not copying rest of the operands, just conditional code. Signed-off-by: Vladimir Radosavljevic <[email protected]>
1 parent aa2e1d5 commit 1b49bbc

File tree

3 files changed

+66
-8
lines changed

3 files changed

+66
-8
lines changed

llvm/lib/Target/EraVM/EraVMCombineAddressingMode.cpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -198,17 +198,21 @@ void EraVMCombineAddressingMode::mergeSelect(
198198
*Base.getParent(), Base, Base.getDebugLoc(),
199199
TII->get(IsIn0 ? In0Map[Base.getOpcode()] : In1Map[Base.getOpcode()]));
200200
EraVM::copyOperands(NewMI, Base.operands_begin(), EraVM::in0Iterator(Base));
201-
if (IsIn0)
201+
if (IsIn0) {
202202
EraVM::copyOperands(NewMI, In);
203-
else
203+
EraVM::copyOperands(NewMI, EraVM::in1Range(Base));
204+
} else {
204205
EraVM::copyOperands(NewMI, EraVM::in0Range(Base));
205-
if (!IsIn0)
206206
EraVM::copyOperands(NewMI, In);
207-
else
208-
EraVM::copyOperands(NewMI, EraVM::in1Iterator(Base),
209-
Base.operands_begin() + Base.getNumExplicitOperands() -
210-
1);
211-
NewMI.add(Base.getOperand(Base.getNumExplicitOperands() - 1));
207+
}
208+
209+
// Copy the rest of the operands. For select with register output it will be
210+
// only condition code operand, whereas for stack output it will also be the
211+
// output operand.
212+
EraVM::copyOperands(NewMI,
213+
EraVM::in1Iterator(Base) +
214+
argumentSize(EraVM::ArgumentKind::In1, Base),
215+
Base.operands_begin() + Base.getNumExplicitOperands());
212216
}
213217

214218
static bool areEqualStackSlots(MachineInstr::const_mop_iterator It1,

llvm/test/CodeGen/EraVM/def-spill.ll

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,36 @@ define i256 @spill_addr(i256 %a, i256 %b) nounwind {
1717
ret i256 %res
1818
}
1919

20+
; CHECK-LABEL: spill_addr_selirs_use
21+
define i256 @spill_addr_selirs_use(i256 %a, i256 %b, i1 %cond) nounwind {
22+
%slot = alloca i256
23+
; CHECK: add r1, r2, stack-[1]
24+
%x = add i256 %a, %b
25+
; CHECK: sub! r3, r0, r0
26+
; CHECK: add stack-[1], r0, stack-[2]
27+
; CHECK: add.ne 1234, r0, stack-[2]
28+
%sel = select i1 %cond, i256 1234, i256 %x
29+
store i256 %sel, i256* %slot
30+
%c = call i256 @foo()
31+
%res = add i256 %x, %c
32+
ret i256 %res
33+
}
34+
35+
; CHECK-LABEL: spill_addr_selris_use
36+
define i256 @spill_addr_selris_use(i256 %a, i256 %b, i1 %cond) nounwind {
37+
%slot = alloca i256
38+
; CHECK: add r1, r2, stack-[1]
39+
%x = add i256 %a, %b
40+
; CHECK: sub! r3, r0, r0
41+
; CHECK: add 1234, r0, stack-[2]
42+
; CHECK: add.ne stack-[1], r0, stack-[2]
43+
%sel = select i1 %cond, i256 %x, i256 1234
44+
store i256 %sel, i256* %slot
45+
%c = call i256 @foo()
46+
%res = add i256 %x, %c
47+
ret i256 %res
48+
}
49+
2050
; CHECK-LABEL: spill_addi
2151
define i256 @spill_addi(i256 %a) nounwind {
2252
; TODO: CPR-1221 add 42, r2, stack-[1]

llvm/test/CodeGen/EraVM/reload-use.ll

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,30 @@ define i256 @spill_select(i256 %a, i1 %cond) nounwind {
420420
ret i256 %res
421421
}
422422

423+
; CHECK-LABEL: spill_selrrs1
424+
define void @spill_selrrs1(i256 %a, i1 %cond) nounwind {
425+
%slot = alloca i256
426+
%b = call i256 @foo()
427+
; CHECK: sub! stack-[1], r0, r0
428+
; CHECK: add r1, r0, stack-[3]
429+
; CHECK: add.ne stack-[2], r0, stack-[3]
430+
%sel = select i1 %cond, i256 %a, i256 %b
431+
store i256 %sel, i256* %slot
432+
ret void
433+
}
434+
435+
; CHECK-LABEL: spill_selrrs2
436+
define void @spill_selrrs2(i256 %a, i1 %cond) nounwind {
437+
%slot = alloca i256
438+
%b = call i256 @foo()
439+
; CHECK: sub! stack-[1], r0, r0
440+
; CHECK: add stack-[2], r0, stack-[3]
441+
; CHECK: add.ne r1, r0, stack-[3]
442+
%sel = select i1 %cond, i256 %b, i256 %a
443+
store i256 %sel, i256* %slot
444+
ret void
445+
}
446+
423447
; ==============================================================================
424448
; CHECK-LABEL: spill_multiple_use
425449
define void @spill_multiple_use(i256 %a) nounwind {

0 commit comments

Comments
 (0)