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
  233
  234
  235
  236
  237
  238
  239
  240
  241
  242
  243
  244
  245
  246
  247
  248
  249
  250
  251
  252
  253
  254
  255
  256
  257
  258
  259
  260
  261
  262
  263
  264
  265
  266
  267
  268
  269
  270
  271
  272
  273
  274
  275
  276
  277
  278
  279
  280
  281
  282
  283
  284
  285
  286
  287
  288
  289
  290
  291
  292
  293
  294
  295
  296
  297
  298
  299
  300
  301
  302
  303
  304
  305
  306
  307
  308
  309
  310
  311
  312
  313
  314
  315
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt < %s -basicaa -newgvn -S | FileCheck %s
target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"

;; Function Attrs: nounwind ssp uwtable
;; We should eliminate the sub, and one of the phi nodes
define void @vnum_test1(i32* %data) #0 {
; CHECK-LABEL: @vnum_test1(
; CHECK-NEXT:  bb:
; CHECK-NEXT:    [[TMP:%.*]] = getelementptr inbounds i32, i32* [[DATA:%.*]], i64 3
; CHECK-NEXT:    [[TMP1:%.*]] = load i32, i32* [[TMP]], align 4
; CHECK-NEXT:    [[TMP2:%.*]] = getelementptr inbounds i32, i32* [[DATA]], i64 4
; CHECK-NEXT:    [[TMP3:%.*]] = load i32, i32* [[TMP2]], align 4
; CHECK-NEXT:    br label [[BB4:%.*]]
; CHECK:       bb4:
; CHECK-NEXT:    [[M_0:%.*]] = phi i32 [ [[TMP3]], [[BB:%.*]] ], [ [[TMP15:%.*]], [[BB17:%.*]] ]
; CHECK-NEXT:    [[I_0:%.*]] = phi i32 [ 0, [[BB]] ], [ [[TMP18:%.*]], [[BB17]] ]
; CHECK-NEXT:    [[TMP5:%.*]] = icmp slt i32 [[I_0]], [[TMP1]]
; CHECK-NEXT:    br i1 [[TMP5]], label [[BB6:%.*]], label [[BB19:%.*]]
; CHECK:       bb6:
; CHECK-NEXT:    [[TMP7:%.*]] = getelementptr inbounds i32, i32* [[DATA]], i64 2
; CHECK-NEXT:    [[TMP8:%.*]] = load i32, i32* [[TMP7]], align 4
; CHECK-NEXT:    [[TMP9:%.*]] = sext i32 [[TMP8]] to i64
; CHECK-NEXT:    [[TMP10:%.*]] = getelementptr inbounds i32, i32* [[DATA]], i64 [[TMP9]]
; CHECK-NEXT:    store i32 2, i32* [[TMP10]], align 4
; CHECK-NEXT:    store i32 0, i32* [[DATA]], align 4
; CHECK-NEXT:    [[TMP13:%.*]] = getelementptr inbounds i32, i32* [[DATA]], i64 1
; CHECK-NEXT:    [[TMP14:%.*]] = load i32, i32* [[TMP13]], align 4
; CHECK-NEXT:    [[TMP15]] = add nsw i32 [[M_0]], [[TMP14]]
; CHECK-NEXT:    br label [[BB17]]
; CHECK:       bb17:
; CHECK-NEXT:    [[TMP18]] = add nsw i32 [[I_0]], 1
; CHECK-NEXT:    br label [[BB4]]
; CHECK:       bb19:
; CHECK-NEXT:    ret void
;
bb:
  %tmp = getelementptr inbounds i32, i32* %data, i64 3
  %tmp1 = load i32, i32* %tmp, align 4
  %tmp2 = getelementptr inbounds i32, i32* %data, i64 4
  %tmp3 = load i32, i32* %tmp2, align 4
  br label %bb4

bb4:                                              ; preds = %bb17, %bb
  %m.0 = phi i32 [ %tmp3, %bb ], [ %tmp15, %bb17 ]
  %i.0 = phi i32 [ 0, %bb ], [ %tmp18, %bb17 ]
  %n.0 = phi i32 [ %tmp3, %bb ], [ %tmp16, %bb17 ]
  %tmp5 = icmp slt i32 %i.0, %tmp1
  br i1 %tmp5, label %bb6, label %bb19

bb6:                                              ; preds = %bb4
  %tmp7 = getelementptr inbounds i32, i32* %data, i64 2
  %tmp8 = load i32, i32* %tmp7, align 4
  %tmp9 = sext i32 %tmp8 to i64
  %tmp10 = getelementptr inbounds i32, i32* %data, i64 %tmp9
  store i32 2, i32* %tmp10, align 4
  %tmp11 = sub nsw i32 %m.0, %n.0
  %tmp12 = getelementptr inbounds i32, i32* %data, i64 0
  store i32 %tmp11, i32* %tmp12, align 4
  %tmp13 = getelementptr inbounds i32, i32* %data, i64 1
  %tmp14 = load i32, i32* %tmp13, align 4
  %tmp15 = add nsw i32 %m.0, %tmp14
  %tmp16 = add nsw i32 %n.0, %tmp14
  br label %bb17

bb17:                                             ; preds = %bb6
  %tmp18 = add nsw i32 %i.0, 1
  br label %bb4

bb19:                                             ; preds = %bb4
  ret void
}

;; Function Attrs: nounwind ssp uwtable
;; We should eliminate the sub, one of the phi nodes, prove the store of the sub
;; and the load of data are equivalent, that the load always produces constant 0, and
;; delete the load replacing it with constant 0.
define i32 @vnum_test2(i32* %data) #0 {
; CHECK-LABEL: @vnum_test2(
; CHECK-NEXT:  bb:
; CHECK-NEXT:    [[TMP:%.*]] = getelementptr inbounds i32, i32* [[DATA:%.*]], i64 3
; CHECK-NEXT:    [[TMP1:%.*]] = load i32, i32* [[TMP]], align 4
; CHECK-NEXT:    [[TMP2:%.*]] = getelementptr inbounds i32, i32* [[DATA]], i64 4
; CHECK-NEXT:    [[TMP3:%.*]] = load i32, i32* [[TMP2]], align 4
; CHECK-NEXT:    br label [[BB4:%.*]]
; CHECK:       bb4:
; CHECK-NEXT:    [[M_0:%.*]] = phi i32 [ [[TMP3]], [[BB:%.*]] ], [ [[TMP15:%.*]], [[BB19:%.*]] ]
; CHECK-NEXT:    [[I_0:%.*]] = phi i32 [ 0, [[BB]] ], [ [[TMP20:%.*]], [[BB19]] ]
; CHECK-NEXT:    [[TMP5:%.*]] = icmp slt i32 [[I_0]], [[TMP1]]
; CHECK-NEXT:    br i1 [[TMP5]], label [[BB6:%.*]], label [[BB21:%.*]]
; CHECK:       bb6:
; CHECK-NEXT:    [[TMP7:%.*]] = getelementptr inbounds i32, i32* [[DATA]], i64 2
; CHECK-NEXT:    [[TMP8:%.*]] = load i32, i32* [[TMP7]], align 4
; CHECK-NEXT:    [[TMP9:%.*]] = sext i32 [[TMP8]] to i64
; CHECK-NEXT:    [[TMP10:%.*]] = getelementptr inbounds i32, i32* [[DATA]], i64 [[TMP9]]
; CHECK-NEXT:    store i32 2, i32* [[TMP10]], align 4
; CHECK-NEXT:    store i32 0, i32* [[DATA]], align 4
; CHECK-NEXT:    [[TMP13:%.*]] = getelementptr inbounds i32, i32* [[DATA]], i64 1
; CHECK-NEXT:    [[TMP14:%.*]] = load i32, i32* [[TMP13]], align 4
; CHECK-NEXT:    [[TMP15]] = add nsw i32 [[M_0]], [[TMP14]]
; CHECK-NEXT:    br label [[BB19]]
; CHECK:       bb19:
; CHECK-NEXT:    [[TMP20]] = add nsw i32 [[I_0]], 1
; CHECK-NEXT:    br label [[BB4]]
; CHECK:       bb21:
; CHECK-NEXT:    ret i32 0
;
bb:
  %tmp = getelementptr inbounds i32, i32* %data, i64 3
  %tmp1 = load i32, i32* %tmp, align 4
  %tmp2 = getelementptr inbounds i32, i32* %data, i64 4
  %tmp3 = load i32, i32* %tmp2, align 4
  br label %bb4

bb4:                                              ; preds = %bb19, %bb
  %m.0 = phi i32 [ %tmp3, %bb ], [ %tmp15, %bb19 ]
  %n.0 = phi i32 [ %tmp3, %bb ], [ %tmp16, %bb19 ]
  %i.0 = phi i32 [ 0, %bb ], [ %tmp20, %bb19 ]
  %p.0 = phi i32 [ undef, %bb ], [ %tmp18, %bb19 ]
  %tmp5 = icmp slt i32 %i.0, %tmp1
  br i1 %tmp5, label %bb6, label %bb21

bb6:                                              ; preds = %bb4
  %tmp7 = getelementptr inbounds i32, i32* %data, i64 2
  %tmp8 = load i32, i32* %tmp7, align 4
  %tmp9 = sext i32 %tmp8 to i64
  %tmp10 = getelementptr inbounds i32, i32* %data, i64 %tmp9
  store i32 2, i32* %tmp10, align 4
  %tmp11 = sub nsw i32 %m.0, %n.0
  %tmp12 = getelementptr inbounds i32, i32* %data, i64 0
  store i32 %tmp11, i32* %tmp12, align 4
  %tmp13 = getelementptr inbounds i32, i32* %data, i64 1
  %tmp14 = load i32, i32* %tmp13, align 4
  %tmp15 = add nsw i32 %m.0, %tmp14
  %tmp16 = add nsw i32 %n.0, %tmp14
  %tmp17 = getelementptr inbounds i32, i32* %data, i64 0
  %tmp18 = load i32, i32* %tmp17, align 4
  br label %bb19

bb19:                                             ; preds = %bb6
  %tmp20 = add nsw i32 %i.0, 1
  br label %bb4

bb21:                                             ; preds = %bb4
  ret i32 %p.0
}


; Function Attrs: nounwind ssp uwtable
;; Same as test 2, with a conditional store of m-n, so it has to also discover
;; that data ends up with the same value no matter what branch is taken.
define i32 @vnum_test3(i32* %data) #0 {
; CHECK-LABEL: @vnum_test3(
; CHECK-NEXT:  bb:
; CHECK-NEXT:    [[TMP:%.*]] = getelementptr inbounds i32, i32* [[DATA:%.*]], i64 3
; CHECK-NEXT:    [[TMP1:%.*]] = load i32, i32* [[TMP]], align 4
; CHECK-NEXT:    [[TMP2:%.*]] = getelementptr inbounds i32, i32* [[DATA]], i64 4
; CHECK-NEXT:    [[TMP3:%.*]] = load i32, i32* [[TMP2]], align 4
; CHECK-NEXT:    br label [[BB4:%.*]]
; CHECK:       bb4:
; CHECK-NEXT:    [[N_0:%.*]] = phi i32 [ [[TMP3]], [[BB:%.*]] ], [ [[TMP19:%.*]], [[BB21:%.*]] ]
; CHECK-NEXT:    [[I_0:%.*]] = phi i32 [ 0, [[BB]] ], [ [[TMP22:%.*]], [[BB21]] ]
; CHECK-NEXT:    [[TMP5:%.*]] = icmp slt i32 [[I_0]], [[TMP1]]
; CHECK-NEXT:    br i1 [[TMP5]], label [[BB6:%.*]], label [[BB23:%.*]]
; CHECK:       bb6:
; CHECK-NEXT:    [[TMP7:%.*]] = getelementptr inbounds i32, i32* [[DATA]], i64 2
; CHECK-NEXT:    [[TMP9:%.*]] = getelementptr inbounds i32, i32* [[DATA]], i64 5
; CHECK-NEXT:    store i32 0, i32* [[TMP9]], align 4
; CHECK-NEXT:    [[TMP10:%.*]] = icmp slt i32 [[I_0]], 30
; CHECK-NEXT:    br i1 [[TMP10]], label [[BB11:%.*]], label [[BB14:%.*]]
; CHECK:       bb11:
; CHECK-NEXT:    br label [[BB14]]
; CHECK:       bb14:
; CHECK-NEXT:    [[TMP17:%.*]] = getelementptr inbounds i32, i32* [[DATA]], i64 1
; CHECK-NEXT:    [[TMP18:%.*]] = load i32, i32* [[TMP17]], align 4
; CHECK-NEXT:    [[TMP19]] = add nsw i32 [[N_0]], [[TMP18]]
; CHECK-NEXT:    br label [[BB21]]
; CHECK:       bb21:
; CHECK-NEXT:    [[TMP22]] = add nsw i32 [[I_0]], 1
; CHECK-NEXT:    br label [[BB4]]
; CHECK:       bb23:
; CHECK-NEXT:    ret i32 0
;
bb:
  %tmp = getelementptr inbounds i32, i32* %data, i64 3
  %tmp1 = load i32, i32* %tmp, align 4
  %tmp2 = getelementptr inbounds i32, i32* %data, i64 4
  %tmp3 = load i32, i32* %tmp2, align 4
  br label %bb4

bb4:                                              ; preds = %bb21, %bb
  %n.0 = phi i32 [ %tmp3, %bb ], [ %tmp20, %bb21 ]
  %m.0 = phi i32 [ %tmp3, %bb ], [ %tmp19, %bb21 ]
  %p.0 = phi i32 [ 0, %bb ], [ %tmp16, %bb21 ]
  %i.0 = phi i32 [ 0, %bb ], [ %tmp22, %bb21 ]
  %tmp5 = icmp slt i32 %i.0, %tmp1
  br i1 %tmp5, label %bb6, label %bb23

bb6:                                              ; preds = %bb4
  %tmp7 = getelementptr inbounds i32, i32* %data, i64 2
  %tmp8 = load i32, i32* %tmp7, align 4
  %tmp9 = getelementptr inbounds i32, i32* %data, i64 5
  store i32 0, i32* %tmp9, align 4
  %tmp10 = icmp slt i32 %i.0, 30
  br i1 %tmp10, label %bb11, label %bb14

bb11:                                             ; preds = %bb6
  %tmp12 = sub nsw i32 %m.0, %n.0
  %tmp13 = getelementptr inbounds i32, i32* %data, i64 5
  store i32 %tmp12, i32* %tmp13, align 4
  br label %bb14

bb14:                                             ; preds = %bb11, %bb6
  %tmp15 = getelementptr inbounds i32, i32* %data, i64 5
  %tmp16 = load i32, i32* %tmp15, align 4
  %tmp17 = getelementptr inbounds i32, i32* %data, i64 1
  %tmp18 = load i32, i32* %tmp17, align 4
  %tmp19 = add nsw i32 %m.0, %tmp18
  %tmp20 = add nsw i32 %n.0, %tmp18
  br label %bb21

bb21:                                             ; preds = %bb14
  %tmp22 = add nsw i32 %i.0, 1
  br label %bb4

bb23:                                             ; preds = %bb4
  ret i32 %p.0
}

;; This is an irreducible test case that will cause a memoryphi node loop
;; in the two blocks.
;; It's equivalent to something like
;; *a = 0
;; if (<....>) goto loopmiddle
;; loopstart:
;; loopmiddle:
;; load *a
;; *a = 0
;; if (<....>) goto loopstart otherwise goto loopend
;; loopend:
;; load *a
;; add the results of the loads
;; return them
;;
;; Both loads should equal 0, but it requires being
;; completely optimistic about MemoryPhis, otherwise
;; we will not be able to see through the cycle.
define i8 @irreducible_memoryphi(i8* noalias %arg, i8* noalias %arg2) {
; CHECK-LABEL: @irreducible_memoryphi(
; CHECK-NEXT:  bb:
; CHECK-NEXT:    store i8 0, i8* [[ARG:%.*]]
; CHECK-NEXT:    br i1 undef, label [[BB2:%.*]], label [[BB1:%.*]]
; CHECK:       bb1:
; CHECK-NEXT:    br label [[BB2]]
; CHECK:       bb2:
; CHECK-NEXT:    br i1 undef, label [[BB1]], label [[BB3:%.*]]
; CHECK:       bb3:
; CHECK-NEXT:    ret i8 0
;
bb:
  store i8 0, i8 *%arg
  br i1 undef, label %bb2, label %bb1

bb1:                                              ; preds = %bb2, %bb
  br label %bb2

bb2:                                              ; preds = %bb1, %bb
  %tmp2 = load i8, i8* %arg
  store i8 0, i8 *%arg
  br i1 undef, label %bb1, label %bb3

bb3:                                              ; preds = %bb2
  %tmp = load i8, i8* %arg
  %tmp3 = add i8 %tmp, %tmp2
  ret i8 %tmp3
}
;; This is an irreducible test case that will cause a phi node loop
;; in the two blocks
;;
;; It should return 0, but it requires being
;; completely optimistic about phis, otherwise
;; we will not be able to see through the cycle.
define i32 @irreducible_phi(i32 %arg) {
; CHECK-LABEL: @irreducible_phi(
; CHECK-NEXT:  bb:
; CHECK-NEXT:    br i1 undef, label [[BB2:%.*]], label [[BB1:%.*]]
; CHECK:       bb1:
; CHECK-NEXT:    br label [[BB2]]
; CHECK:       bb2:
; CHECK-NEXT:    br i1 undef, label [[BB1]], label [[BB3:%.*]]
; CHECK:       bb3:
; CHECK-NEXT:    ret i32 0
;
bb:
  %tmp = add i32 0, %arg
  br i1 undef, label %bb2, label %bb1

bb1:                                              ; preds = %bb2, %bb
  %phi1 = phi i32 [%tmp, %bb], [%phi2, %bb2]
  br label %bb2

bb2:                                              ; preds = %bb1, %bb
  %phi2 = phi i32 [%tmp, %bb], [%phi1, %bb1]
  br i1 undef, label %bb1, label %bb3

bb3:                                              ; preds = %bb2
  ; This should be zero
  %tmp3 = sub i32 %tmp, %phi2
  ret i32 %tmp3
}
attributes #0 = { nounwind ssp uwtable "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }

!llvm.ident = !{!0, !0, !0}

!0 = !{!"Apple LLVM version 6.0 (clang-600.0.56) (based on LLVM 3.5svn)"}