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
; RUN: opt -gvn-sink -S < %s | FileCheck %s

%struct = type {i32, i32}
%struct2 = type { [ 2 x i32], i32 }

; Struct indices cannot be variant.

; CHECK-LABEL: @f() {
; CHECK: getelementptr
; CHECK: getelementptr
define void @f() {
bb:
  br i1 undef, label %bb2, label %bb1

bb1:                                              ; preds = %bb
  %tmp = getelementptr inbounds %struct, %struct* null, i64 0, i32 1
  br label %bb4

bb2:                                              ; preds = %bb
  %tmp3 = getelementptr inbounds %struct, %struct* null, i64 0, i32 0
  br label %bb4

bb4:                                              ; preds = %bb2, %bb1
  %tmp5 = phi i32 [ 1, %bb1 ], [ 0, %bb2 ]
  ret void
}

; Struct indices cannot be variant.

; CHECK-LABEL: @g() {
; CHECK: getelementptr
; CHECK: getelementptr
define void @g() {
bb:
  br i1 undef, label %bb2, label %bb1

bb1:                                              ; preds = %bb
  %tmp = getelementptr inbounds %struct2, %struct2* null, i64 0, i32 0, i32 1
  br label %bb4

bb2:                                              ; preds = %bb
  %tmp3 = getelementptr inbounds %struct2, %struct2* null, i64 0, i32 0, i32 0
  br label %bb4

bb4:                                              ; preds = %bb2, %bb1
  %tmp5 = phi i32 [ 1, %bb1 ], [ 0, %bb2 ]
  ret void
}


; ... but the first parameter to a GEP can.

; CHECK-LABEL: @h() {
; CHECK: getelementptr
; CHECK-NOT: getelementptr
define void @h() {
bb:
  br i1 undef, label %bb2, label %bb1

bb1:                                              ; preds = %bb
  %tmp = getelementptr inbounds %struct, %struct* null, i32 0, i32 0
  br label %bb4

bb2:                                              ; preds = %bb
  %tmp3 = getelementptr inbounds %struct, %struct* null, i32 1, i32 0
  br label %bb4

bb4:                                              ; preds = %bb2, %bb1
  %tmp5 = phi i32 [ 0, %bb1 ], [ 1, %bb2 ]
  ret void
}