reference, declarationdefinition
definition → references, declarations, derived classes, virtual overrides
reference to multiple definitions → definitions
unreferenced
    1
    2
    3
    4
    5
    6
    7
    8
    9
   10
   11
   12
   13
   14
   15
   16
   17
   18
   19
   20
   21
   22
   23
   24
   25
   26
   27
   28
   29
   30
   31
   32
   33
   34
   35
   36
   37
   38
   39
   40
   41
   42
   43
   44
   45
   46
   47
   48
   49
   50
   51
   52
   53
   54
   55
   56
   57
   58
   59
   60
   61
   62
   63
   64
   65
   66
   67
   68
   69
   70
   71
   72
   73
   74
   75
   76
   77
   78
   79
   80
   81
   82
   83
   84
   85
   86
   87
   88
   89
   90
   91
   92
   93
   94
   95
   96
   97
   98
   99
  100
  101
  102
  103
  104
  105
  106
  107
  108
  109
  110
  111
  112
  113
  114
  115
  116
  117
  118
  119
  120
  121
  122
  123
  124
  125
  126
  127
  128
  129
  130
  131
  132
  133
  134
  135
  136
  137
  138
  139
  140
  141
  142
  143
  144
  145
  146
  147
  148
  149
  150
  151
  152
  153
  154
  155
  156
  157
  158
  159
  160
  161
  162
  163
  164
  165
  166
  167
  168
  169
  170
  171
  172
  173
  174
  175
  176
  177
  178
  179
  180
  181
  182
  183
  184
  185
  186
  187
  188
  189
  190
  191
  192
  193
  194
  195
  196
  197
  198
  199
  200
  201
  202
  203
  204
  205
  206
  207
  208
  209
  210
  211
  212
  213
  214
  215
  216
  217
  218
  219
  220
  221
  222
  223
  224
  225
  226
  227
  228
  229
  230
  231
  232
# RUN: llc -mtriple=x86_64-- -run-pass=peephole-opt -o - %s | FileCheck %s

--- |
  define i32 @foo(i32 %a) {
  bb0:
    br label %bb1

  bb1:                                              ; preds = %bb7, %bb0
    %vreg0 = phi i32 [ 0, %bb0 ], [ %vreg3, %bb7 ]
    %cond0 = icmp eq i32 %a, 0
    br i1 %cond0, label %bb4, label %bb3

  bb3:                                              ; preds = %bb1
    br label %bb4

  bb4:                                              ; preds = %bb1, %bb3
    %vreg5 = phi i32 [ 2, %bb3 ], [ 1, %bb1 ]
    %cond1 = icmp eq i32 %vreg5, 0
    br i1 %cond1, label %bb7, label %bb6

  bb6:                                              ; preds = %bb4
    br label %bb7

  bb7:                                              ; preds = %bb4, %bb6
    %vreg1 = phi i32 [ 2, %bb6 ], [ 1, %bb4 ]
    %vreg2 = add i32 %vreg5, %vreg0
    %vreg3 = add i32 %vreg1, %vreg2
    %cond2 = icmp slt i32 %vreg3, 10
    br i1 %cond2, label %bb1, label %bb8

  bb8:                                              ; preds = %bb7
    ret i32 0
  }

  define i32 @bar(i32 %a, i32* %p) {
  bb0:
    br label %bb1

  bb1:                                              ; preds = %bb7, %bb0
    %vreg0 = phi i32 [ 0, %bb0 ], [ %vreg3, %bb7 ]
    %cond0 = icmp eq i32 %a, 0
    br i1 %cond0, label %bb4, label %bb3

  bb3:                                              ; preds = %bb1
    br label %bb4

  bb4:                                              ; preds = %bb1, %bb3
    %vreg5 = phi i32 [ 2, %bb3 ], [ 1, %bb1 ]
    %cond1 = icmp eq i32 %vreg5, 0
    br i1 %cond1, label %bb7, label %bb6

  bb6:                                              ; preds = %bb4
    br label %bb7

  bb7:                                              ; preds = %bb4, %bb6
    %vreg1 = phi i32 [ 2, %bb6 ], [ 1, %bb4 ]
    %vreg2 = add i32 %vreg5, %vreg0
    store i32 %vreg0, i32* %p
    %vreg3 = add i32 %vreg1, %vreg2
    %cond2 = icmp slt i32 %vreg3, 10
    br i1 %cond2, label %bb1, label %bb8

  bb8:                                              ; preds = %bb7
    ret i32 0
  }

...
---
# There is a recurrence formulated around %0, %10, and %3. Check that operands
# are commuted for ADD instructions in bb.5.bb7 so that the values involved in
# the recurrence are tied. This will remove redundant copy instruction.
name:            foo
tracksRegLiveness: true
registers:
  - { id: 0, class: gr32, preferred-register: '' }
  - { id: 1, class: gr32, preferred-register: '' }
  - { id: 2, class: gr32, preferred-register: '' }
  - { id: 3, class: gr32, preferred-register: '' }
  - { id: 4, class: gr32, preferred-register: '' }
  - { id: 5, class: gr32, preferred-register: '' }
  - { id: 6, class: gr32, preferred-register: '' }
  - { id: 7, class: gr32, preferred-register: '' }
  - { id: 8, class: gr32, preferred-register: '' }
  - { id: 9, class: gr32, preferred-register: '' }
  - { id: 10, class: gr32, preferred-register: '' }
  - { id: 11, class: gr32, preferred-register: '' }
  - { id: 12, class: gr32, preferred-register: '' }
liveins:
  - { reg: '$edi', virtual-reg: '%4' }
body:             |
  bb.0.bb0:
    successors: %bb.1(0x80000000)
    liveins: $edi

    %4 = COPY $edi
    %5 = MOV32r0 implicit-def dead $eflags

  bb.1.bb1:
    successors: %bb.3(0x30000000), %bb.2(0x50000000)

    ; CHECK: %0:gr32 = PHI %5, %bb.0, %3, %bb.5
    %0 = PHI %5, %bb.0, %3, %bb.5
    %6 = MOV32ri 1
    TEST32rr %4, %4, implicit-def $eflags
    JCC_1 %bb.3, 4, implicit $eflags
    JMP_1 %bb.2

  bb.2.bb3:
    successors: %bb.3(0x80000000)

    %7 = MOV32ri 2

  bb.3.bb4:
    successors: %bb.5(0x30000000), %bb.4(0x50000000)

    %1 = PHI %6, %bb.1, %7, %bb.2
    TEST32rr %1, %1, implicit-def $eflags
    JCC_1 %bb.5, 4, implicit $eflags
    JMP_1 %bb.4

  bb.4.bb6:
    successors: %bb.5(0x80000000)

    %9 = MOV32ri 2

  bb.5.bb7:
    successors: %bb.1(0x7c000000), %bb.6(0x04000000)

    %2 = PHI %6, %bb.3, %9, %bb.4
    %10 = ADD32rr %1, %0, implicit-def dead $eflags
    ; CHECK: %10:gr32 = ADD32rr
    ; CHECK-SAME: %0,
    ; CHECK-SAME: %1,
    %3 = ADD32rr %2, killed %10, implicit-def dead $eflags
    ; CHECK: %3:gr32 = ADD32rr
    ; CHECK-SAME: %10,
    ; CHECK-SAME: %2,
    %11 = SUB32ri8 %3, 10, implicit-def $eflags
    JCC_1 %bb.1, 12, implicit $eflags
    JMP_1 %bb.6

  bb.6.bb8:
    %12 = MOV32r0 implicit-def dead $eflags
    $eax = COPY %12
    RET 0, $eax

...
---
# Here a recurrence is formulated around %0, %11, and %3, but operands should
# not be commuted because %0 has a use outside of recurrence. This is to
# prevent the case of commuting operands ties the values with overlapping live
# ranges.
name:            bar
tracksRegLiveness: true
registers:
  - { id: 0, class: gr32, preferred-register: '' }
  - { id: 1, class: gr32, preferred-register: '' }
  - { id: 2, class: gr32, preferred-register: '' }
  - { id: 3, class: gr32, preferred-register: '' }
  - { id: 4, class: gr32, preferred-register: '' }
  - { id: 5, class: gr64, preferred-register: '' }
  - { id: 6, class: gr32, preferred-register: '' }
  - { id: 7, class: gr32, preferred-register: '' }
  - { id: 8, class: gr32, preferred-register: '' }
  - { id: 9, class: gr32, preferred-register: '' }
  - { id: 10, class: gr32, preferred-register: '' }
  - { id: 11, class: gr32, preferred-register: '' }
  - { id: 12, class: gr32, preferred-register: '' }
  - { id: 13, class: gr32, preferred-register: '' }
liveins:
  - { reg: '$edi', virtual-reg: '%4' }
  - { reg: '$rsi', virtual-reg: '%5' }
body:             |
  bb.0.bb0:
    successors: %bb.1(0x80000000)
    liveins: $edi, $rsi

    %5 = COPY $rsi
    %4 = COPY $edi
    %6 = MOV32r0 implicit-def dead $eflags

  bb.1.bb1:
    successors: %bb.3(0x30000000), %bb.2(0x50000000)

    %0 = PHI %6, %bb.0, %3, %bb.5
    ; CHECK: %0:gr32 = PHI %6, %bb.0, %3, %bb.5
    %7 = MOV32ri 1
    TEST32rr %4, %4, implicit-def $eflags
    JCC_1 %bb.3, 4, implicit $eflags
    JMP_1 %bb.2

  bb.2.bb3:
    successors: %bb.3(0x80000000)

    %8 = MOV32ri 2

  bb.3.bb4:
    successors: %bb.5(0x30000000), %bb.4(0x50000000)

    %1 = PHI %7, %bb.1, %8, %bb.2
    TEST32rr %1, %1, implicit-def $eflags
    JCC_1 %bb.5, 4, implicit $eflags
    JMP_1 %bb.4

  bb.4.bb6:
    successors: %bb.5(0x80000000)

    %10 = MOV32ri 2

  bb.5.bb7:
    successors: %bb.1(0x7c000000), %bb.6(0x04000000)

    %2 = PHI %7, %bb.3, %10, %bb.4
    %11 = ADD32rr %1, %0, implicit-def dead $eflags
    ; CHECK: %11:gr32 = ADD32rr
    ; CHECK-SAME: %1,
    ; CHECK-SAME: %0,
    MOV32mr %5, 1, $noreg, 0, $noreg, %0 :: (store 4 into %ir.p)
    %3 = ADD32rr %2, killed %11, implicit-def dead $eflags
    ; CHECK: %3:gr32 = ADD32rr
    ; CHECK-SAME: %2,
    ; CHECK-SAME: %11,
    %12 = SUB32ri8 %3, 10, implicit-def $eflags
    JCC_1 %bb.1, 12, implicit $eflags
    JMP_1 %bb.6

  bb.6.bb8:
    %13 = MOV32r0 implicit-def dead $eflags
    $eax = COPY %13
    RET 0, $eax

...