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
; Test that accesses of the stack remain within the range defined by R1,
; i.e. that loads and stores only access the allocated stack. This does not
; have to be the case when red zone is present.

; Make sure that there is no red zone, i.e. ppc32 and SVR4 ABI.
; RUN: llc -mtriple=powerpc--freebsd-elf < %s | FileCheck %s

; There are two ways that the stack pointer can be adjusted in the prologue:
; - by adding an immediate value:
;     stwu r1, -imm(r1)
; - by adding another register:
;     stwux r1, rx, r1
;
; The restoring of the stack pointer can be done:
; - by adding an immediate value to it:
;     addi r1, r1, imm
; - by copying the value from another register:
;     mr r1, rx


; Nothing (no special features).
;
; CHECK-LABEL: test_n:
; CHECK-NOT: stw {{[0-9]+}}, -{{[0-9]+}}(1)
; CHECK: stwu 1, -[[SIZE:[0-9]+]](1)
; CHECK: addi 1, 1, [[SIZE]]
; CHECK-NOT: lwz {{[0-9]+}}, -{{[0-9]+}}(1)
define i32 @test_n() local_unnamed_addr #0 {
entry:
  %t0 = tail call i32 bitcast (i32 (...)* @bar0 to i32 ()*)() #0
  ret i32 %t0
}

; Aligned object on the stack.
;
; CHECK-LABEL: test_a:
; CHECK-NOT: stw {{[0-9]+}}, -{{[0-9]+}}(1)
; CHECK: stwux 1, 1, {{[0-9]+}}
; CHECK: mr 1, {{[0-9]+}}
; CHECK-NOT: lwz {{[0-9]+}}, -{{[0-9]+}}(1)

define i32 @test_a() local_unnamed_addr #0 {
entry:
  %t0 = alloca i32, align 128
  %t1 = tail call i32 bitcast (i32 (...)* @bar1 to i32 (i32*)*)(i32* %t0) #0
  ret i32 %t1
}

; Dynamic allocation on the stack.
;
; CHECK-LABEL: test_d:
; CHECK-NOT: stw {{[0-9]+}}, -{{[0-9]+}}(1)
; CHECK: stwu 1, -[[SIZE:[0-9]+]](1)
; CHECK: mr 1, {{[0-9]+}}
; CHECK-NOT: lwz {{[0-9]+}}, -{{[0-9]+}}(1)
define i32 @test_d(i32 %p0) local_unnamed_addr #0 {
  %t0 = alloca i32, i32 %p0, align 4
  %t1 = tail call i32 bitcast (i32 (...)* @bar1 to i32 (i32*)*)(i32* %t0) #0
  ret i32 %t1
}

; Large stack (exceeds size of D-field).
; CHECK-LABEL: test_s:
; CHECK-NOT: stw {{[0-9]+}}, -{{[0-9]+}}(1)
; CHECK: stwux 1, 1, {{[0-9]+}}
; CHECK: mr 1, {{[0-9]+}}
; CHECK-NOT: lwz {{[0-9]+}}, -{{[0-9]+}}(1)
define i32 @test_s(i32 %p0) local_unnamed_addr #0 {
entry:
  %t0 = alloca [16384 x i32]
  %t1 = getelementptr [16384 x i32], [16384 x i32]* %t0, i32 0, i32 0
  %t2 = tail call i32 bitcast (i32 (...)* @bar1 to i32 (i32*)*)(i32* %t1) #0
  ret i32 %t2
}

; Combinations.

; CHECK-LABEL: test_ad:
; CHECK-NOT: stw {{[0-9]+}}, -{{[0-9]+}}(1)
; CHECK: stwux 1, 1, {{[0-9]+}}
; CHECK: mr 1, {{[0-9]+}}
; CHECK-NOT: lwz {{[0-9]+}}, -{{[0-9]+}}(1)
define i32 @test_ad(i32 %p0) local_unnamed_addr #0 {
  %t0 = alloca i32, align 128
  %t1 = alloca i32, i32 %p0, align 4
  %t2 = tail call i32 bitcast (i32 (...)* @bar1 to i32 (i32*)*)(i32* %t0) #0
  %t3 = tail call i32 bitcast (i32 (...)* @bar1 to i32 (i32*)*)(i32* %t1) #0
  %t4 = add i32 %t2, %t3
  ret i32 %t4
}

; CHECK-LABEL: test_as:
; CHECK-NOT: stw {{[0-9]+}}, -{{[0-9]+}}(1)
; CHECK: stwux 1, 1, {{[0-9]+}}
; CHECK: mr 1, {{[0-9]+}}
; CHECK-NOT: lwz {{[0-9]+}}, -{{[0-9]+}}(1)
define i32 @test_as() local_unnamed_addr #0 {
  %t0 = alloca i32, align 128
  %t1 = alloca [16384 x i32]
  %t2 = tail call i32 bitcast (i32 (...)* @bar1 to i32 (i32*)*)(i32* %t0) #0
  %t3 = getelementptr [16384 x i32], [16384 x i32]* %t1, i32 0, i32 0
  %t4 = tail call i32 bitcast (i32 (...)* @bar1 to i32 (i32*)*)(i32* %t3) #0
  %t5 = add i32 %t2, %t4
  ret i32 %t5
}

; CHECK-LABEL: test_ds:
; CHECK-NOT: stw {{[0-9]+}}, -{{[0-9]+}}(1)
; CHECK: stwux 1, 1, {{[0-9]+}}
; CHECK: mr 1, {{[0-9]+}}
; CHECK-NOT: lwz {{[0-9]+}}, -{{[0-9]+}}(1)
define i32 @test_ds(i32 %p0) local_unnamed_addr #0 {
  %t0 = alloca i32, i32 %p0, align 4
  %t1 = alloca [16384 x i32]
  %t2 = tail call i32 bitcast (i32 (...)* @bar1 to i32 (i32*)*)(i32* %t0) #0
  %t3 = getelementptr [16384 x i32], [16384 x i32]* %t1, i32 0, i32 0
  %t4 = tail call i32 bitcast (i32 (...)* @bar1 to i32 (i32*)*)(i32* %t3) #0
  %t5 = add i32 %t2, %t4
  ret i32 %t5
}

; CHECK-LABEL: test_ads:
; CHECK-NOT: stw {{[0-9]+}}, -{{[0-9]+}}(1)
; CHECK: stwux 1, 1, {{[0-9]+}}
; CHECK: mr 1, {{[0-9]+}}
; CHECK-NOT: lwz {{[0-9]+}}, -{{[0-9]+}}(1)
define i32 @test_ads(i32 %p0) local_unnamed_addr #0 {
  %t0 = alloca i32, align 128
  %t1 = alloca i32, i32 %p0, align 4
  %t2 = alloca [16384 x i32]

  %t3 = tail call i32 bitcast (i32 (...)* @bar1 to i32 (i32*)*)(i32* %t0) #0
  %t4 = tail call i32 bitcast (i32 (...)* @bar1 to i32 (i32*)*)(i32* %t1) #0
  %t5 = add i32 %t3, %t4

  %t6 = getelementptr [16384 x i32], [16384 x i32]* %t2, i32 0, i32 0
  %t7 = tail call i32 bitcast (i32 (...)* @bar1 to i32 (i32*)*)(i32* %t6) #0
  %t8 = add i32 %t5, %t7
  ret i32 %t7
}


declare i32 @bar0(...) local_unnamed_addr #0
declare i32 @bar1(...) local_unnamed_addr #0

attributes #0 = { nounwind }