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
; RUN: opt -codegenprepare -mtriple=arm64_32-apple-ios %s -S -o - | FileCheck %s

define void @test_simple_sink(i1* %base, i64 %offset) {
; CHECK-LABEL: @test_simple_sink
; CHECK: next:
; CHECK:   [[BASE8:%.*]] = bitcast i1* %base to i8*
; CHECK:   [[ADDR8:%.*]] = getelementptr i8, i8* [[BASE8]], i64 %offset
; CHECK:   [[ADDR:%.*]] = bitcast i8* [[ADDR8]] to i1*
; CHECK:   load volatile i1, i1* [[ADDR]]
  %addr = getelementptr i1, i1* %base, i64 %offset
  %tst = load i1, i1* %addr
  br i1 %tst, label %next, label %end

next:
  load volatile i1, i1* %addr
  ret void

end:
  ret void
}

define void @test_inbounds_sink(i1* %base, i64 %offset) {
; CHECK-LABEL: @test_inbounds_sink
; CHECK: next:
; CHECK:   [[BASE8:%.*]] = bitcast i1* %base to i8*
; CHECK:   [[ADDR8:%.*]] = getelementptr inbounds i8, i8* [[BASE8]], i64 %offset
; CHECK:   [[ADDR:%.*]] = bitcast i8* [[ADDR8]] to i1*
; CHECK:   load volatile i1, i1* [[ADDR]]
  %addr = getelementptr inbounds i1, i1* %base, i64 %offset
  %tst = load i1, i1* %addr
  br i1 %tst, label %next, label %end

next:
  load volatile i1, i1* %addr
  ret void

end:
  ret void
}

; No address derived via an add can be guaranteed inbounds
define void @test_add_sink(i1* %base, i64 %offset) {
; CHECK-LABEL: @test_add_sink
; CHECK: next:
; CHECK:   [[BASE8:%.*]] = bitcast i1* %base to i8*
; CHECK:   [[ADDR8:%.*]] = getelementptr i8, i8* [[BASE8]], i64 %offset
; CHECK:   [[ADDR:%.*]] = bitcast i8* [[ADDR8]] to i1*
; CHECK:   load volatile i1, i1* [[ADDR]]
  %base64 = ptrtoint i1* %base to i64
  %addr64 = add nsw nuw i64 %base64, %offset
  %addr = inttoptr i64 %addr64 to i1*
  %tst = load i1, i1* %addr
  br i1 %tst, label %next, label %end

next:
  load volatile i1, i1* %addr
  ret void

end:
  ret void
}