Files
clang-p2996/llvm/test/CodeGen/PowerPC/opt-cmp-rec-postra.mir
esmeyi d1115c2b84 [PowerPC] Optimize compare by using record form in post-RA.
Summary: We currently optimize the comparison only in SSA, therefore we will miss some optimization opportunities where the input of comparison is lowered from COPY in post-RA.
Ie. ExpandPostRA::LowerCopy is called after PPCInstrInfo::optimizeCompareInstr.
This patch optimizes the comparison in post-RA and only the cases that compare against zero can be handled.
D131374 converts the comparison and its user to a compare against zero with the appropriate predicate on the branch, which creates additional opportunities for this patch.

Reviewed By: shchenz, lkail

Differential Revision: https://reviews.llvm.org/D131873
2022-10-31 01:33:50 -04:00

143 lines
3.8 KiB
YAML

# RUN: llc -mtriple=powerpc64le-linux-gnu -stop-after ppc-pre-emit-peephole %s -o - -verify-machineinstrs | FileCheck %s
---
name: test1
# The cmp instr is optimized with the record form.
tracksRegLiveness: true
body: |
bb.0.entry:
successors: %bb.1(0x30000000), %bb.2(0x50000000)
liveins: $x3, $x4
renamable $x3 = OR8 killed renamable $x3, killed renamable $x4
renamable $cr0 = CMPDI renamable $x3, 0, implicit killed $x3
; CHECK-LABEL: name: test1
; CHECK: renamable $x3 = OR8_rec renamable $x3, killed renamable $x4, implicit-def $cr0
; CHECK-NOT: CMPDI
BCC 68, killed renamable $cr0, %bb.2
bb.1:
$x3 = LI8 102
BLR8 implicit $lr8, implicit $rm, implicit $x3
bb.2:
$x3 = LI8 116
BLR8 implicit $lr8, implicit $rm, implicit $x3
...
---
name: test2
# The imm of the comparison instr isn't 0.
tracksRegLiveness: true
body: |
bb.0.entry:
successors: %bb.1(0x30000000), %bb.2(0x50000000)
liveins: $x3, $x4
renamable $x3 = OR8 killed renamable $x3, killed renamable $x4
renamable $cr0 = CMPDI renamable $x3, 2, implicit killed $x3
; CHECK-LABEL: name: test2
; CHECK: CMPDI
BCC 68, killed renamable $cr0, %bb.2
bb.1:
$x3 = LI8 102
BLR8 implicit $lr8, implicit $rm, implicit $x3
bb.2:
$x3 = LI8 116
BLR8 implicit $lr8, implicit $rm, implicit $x3
...
---
name: test3
# The comparison instr has a implicit def.
tracksRegLiveness: true
body: |
bb.0.entry:
successors: %bb.1(0x30000000), %bb.2(0x50000000)
liveins: $x3, $x4
renamable $x3 = OR8 killed renamable $x3, killed renamable $x4
renamable $cr0 = CMPDI renamable $x3, 0, implicit-def $x3
; CHECK-LABEL: name: test3
; CHECK: CMPDI
BCC 68, killed renamable $cr0, %bb.2
bb.1:
$x3 = LI8 102
BLR8 implicit $lr8, implicit $rm, implicit $x3
bb.2:
$x3 = LI8 116
BLR8 implicit $lr8, implicit $rm, implicit $x3
...
---
name: test4
# There is another use for cr0 between OR8 instr and CMPWI instr.
tracksRegLiveness: true
body: |
bb.0.entry:
successors: %bb.1(0x30000000), %bb.2(0x50000000)
liveins: $x3, $x4, $cr0
renamable $x3 = OR8 killed renamable $x3, killed renamable $x4
renamable $cr1 = MCRF killed $cr0, implicit $x3
renamable $cr0 = CMPDI renamable $x3, 0, implicit killed $x3, implicit $cr1
; CHECK-LABEL: name: test4
; CHECK: CMPDI
BCC 68, killed renamable $cr0, %bb.2
bb.1:
$x3 = LI8 102
BLR8 implicit $lr8, implicit $rm, implicit $x3
bb.2:
$x3 = LI8 116
BLR8 implicit $lr8, implicit $rm, implicit $x3
...
---
name: test5
# There is another def for cr0 between OR8 instr and CMPWI instr.
tracksRegLiveness: true
body: |
bb.0.entry:
successors: %bb.1(0x30000000), %bb.2(0x50000000)
liveins: $x3, $x4
renamable $x3 = OR8 killed renamable $x3, renamable $x4
renamable $cr1 = CMPD renamable $x3, renamable $x4, implicit-def $cr0
renamable $cr0 = CMPDI renamable $x3, 0, implicit killed $x3, implicit $cr1
; CHECK-LABEL: name: test5
; CHECK: CMPDI
BCC 68, killed renamable $cr0, %bb.2
bb.1:
$x3 = LI8 102
BLR8 implicit $lr8, implicit $rm, implicit $x3
bb.2:
$x3 = LI8 116
BLR8 implicit $lr8, implicit $rm, implicit $x3
...
---
name: test6
# The SrcReg isn't CR0.
tracksRegLiveness: true
body: |
bb.0.entry:
successors: %bb.1(0x30000000), %bb.2(0x50000000)
liveins: $x3, $x4
renamable $x3 = OR8 killed renamable $x3, killed renamable $x4
renamable $cr1 = CMPDI renamable $x3, 0, implicit killed $x3
; CHECK-LABEL: name: test6
; CHECK: CMPDI
BCC 68, killed renamable $cr1, %bb.2
bb.1:
$x3 = LI8 102
BLR8 implicit $lr8, implicit $rm, implicit $x3
bb.2:
$x3 = LI8 116
BLR8 implicit $lr8, implicit $rm, implicit $x3
...