Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions llvm/lib/Target/RISCV/RISCVISelLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22190,6 +22190,7 @@ static MachineBasicBlock *emitSelectPseudo(MachineInstr &MI,
// - They are debug instructions. Otherwise,
// - They do not have side-effects, do not access memory and their inputs do
// not depend on the results of the select pseudo-instructions.
// - They don't adjust stack.
// The TrueV/FalseV operands of the selects cannot depend on the result of
// previous selects in the sequence.
// These conditions could be further relaxed. See the X86 target for a
Expand Down Expand Up @@ -22218,6 +22219,8 @@ static MachineBasicBlock *emitSelectPseudo(MachineInstr &MI,
SelectDests.insert(MI.getOperand(0).getReg());

MachineInstr *LastSelectPseudo = &MI;
const RISCVInstrInfo &TII = *Subtarget.getInstrInfo();

for (auto E = BB->end(), SequenceMBBI = MachineBasicBlock::iterator(MI);
SequenceMBBI != E; ++SequenceMBBI) {
if (SequenceMBBI->isDebugInstr())
Expand All @@ -22237,15 +22240,16 @@ static MachineBasicBlock *emitSelectPseudo(MachineInstr &MI,
}
if (SequenceMBBI->hasUnmodeledSideEffects() ||
SequenceMBBI->mayLoadOrStore() ||
SequenceMBBI->usesCustomInsertionHook())
SequenceMBBI->usesCustomInsertionHook() ||
TII.isFrameInstr(*SequenceMBBI) ||
SequenceMBBI->isStackAligningInlineAsm())
break;
if (llvm::any_of(SequenceMBBI->operands(), [&](MachineOperand &MO) {
return MO.isReg() && MO.isUse() && SelectDests.count(MO.getReg());
}))
break;
}

const RISCVInstrInfo &TII = *Subtarget.getInstrInfo();
const BasicBlock *LLVM_BB = BB->getBasicBlock();
DebugLoc DL = MI.getDebugLoc();
MachineFunction::iterator I = ++BB->getIterator();
Expand Down
64 changes: 64 additions & 0 deletions llvm/test/CodeGen/RISCV/select-pseudo-merge-with-stack-adj.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 6
; RUN: llc %s -mtriple riscv32 -verify-machineinstrs -o - | FileCheck %s

define i32 @test(i1 %arg_1, i32 %arg_2) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No CHECKs for this file?

; CHECK-LABEL: test:
; CHECK: # %bb.0: # %entry
; CHECK-NEXT: addi sp, sp, -16
; CHECK-NEXT: .cfi_def_cfa_offset 16
; CHECK-NEXT: sw ra, 12(sp) # 4-byte Folded Spill
; CHECK-NEXT: sw s0, 8(sp) # 4-byte Folded Spill
; CHECK-NEXT: sw s1, 4(sp) # 4-byte Folded Spill
; CHECK-NEXT: .cfi_offset ra, -4
; CHECK-NEXT: .cfi_offset s0, -8
; CHECK-NEXT: .cfi_offset s1, -12
; CHECK-NEXT: andi s1, a0, 1
; CHECK-NEXT: mv a0, a1
; CHECK-NEXT: mv s0, a1
; CHECK-NEXT: bnez s1, .LBB0_2
; CHECK-NEXT: # %bb.1: # %entry
; CHECK-NEXT: li s0, 1
; CHECK-NEXT: .LBB0_2: # %entry
; CHECK-NEXT: li a1, 7
; CHECK-NEXT: call __udivsi3
; CHECK-NEXT: bnez s1, .LBB0_4
; CHECK-NEXT: # %bb.3: # %entry
; CHECK-NEXT: li a0, 3
; CHECK-NEXT: .LBB0_4: # %entry
; CHECK-NEXT: bnez s1, .LBB0_6
; CHECK-NEXT: # %bb.5: # %entry
; CHECK-NEXT: mv s0, a0
; CHECK-NEXT: .LBB0_6: # %entry
; CHECK-NEXT: li a0, 3
; CHECK-NEXT: .LBB0_7: # %body
; CHECK-NEXT: # =>This Inner Loop Header: Depth=1
; CHECK-NEXT: addi s0, s0, 4
; CHECK-NEXT: bltu a0, s0, .LBB0_7
; CHECK-NEXT: # %bb.8: # %exit
; CHECK-NEXT: mv a0, s0
; CHECK-NEXT: lw ra, 12(sp) # 4-byte Folded Reload
; CHECK-NEXT: lw s0, 8(sp) # 4-byte Folded Reload
; CHECK-NEXT: lw s1, 4(sp) # 4-byte Folded Reload
; CHECK-NEXT: .cfi_restore ra
; CHECK-NEXT: .cfi_restore s0
; CHECK-NEXT: .cfi_restore s1
; CHECK-NEXT: addi sp, sp, 16
; CHECK-NEXT: .cfi_def_cfa_offset 0
; CHECK-NEXT: ret
entry:
%sel_1 = select i1 %arg_1, i32 %arg_2, i32 1
%div = udiv i32 %arg_2, 7
%cond_1 = icmp ugt i32 %div, %sel_1
%sel_2 = select i1 %arg_1, i32 %div, i32 3
%sel = select i1 %arg_1, i32 %sel_1, i32 %sel_2
br label %body

body:
%res = phi i32 [ %sel, %entry ], [ %add_loop, %body ]
%add_loop = add i32 4, %res
%cond_2 = icmp ugt i32 %add_loop, 3
br i1 %cond_2, label %body, label %exit

exit:
ret i32 %add_loop
}