Home | History | Annotate | Download | only in reader_tests
      1 ; Test if we can read alloca instructions.
      2 
      3 ; RUN: %p2i -i %s --insts | FileCheck %s
      4 ; RUN:   %p2i -i %s --args -notranslate -timing | \
      5 ; RUN:   FileCheck --check-prefix=NOIR %s
      6 
      7 ; Show examples where size is defined by a constant.
      8 
      9 define internal i32 @AllocaA0Size1() {
     10 entry:
     11   %array = alloca i8, i32 1
     12   %addr = ptrtoint i8* %array to i32
     13   ret i32 %addr
     14 
     15 ; CHECK:      entry:
     16 ; CHECK-NEXT:   %array = alloca i8, i32 1
     17 ; CHECK-NEXT:   ret i32 %array
     18 }
     19 
     20 define internal i32 @AllocaA0Size2() {
     21 entry:
     22   %array = alloca i8, i32 2
     23   %addr = ptrtoint i8* %array to i32
     24   ret i32 %addr
     25 
     26 ; CHECK:      entry:
     27 ; CHECK-NEXT:   %array = alloca i8, i32 2
     28 ; CHECK-NEXT:   ret i32 %array
     29 }
     30 
     31 define internal i32 @AllocaA0Size3() {
     32 entry:
     33   %array = alloca i8, i32 3
     34   %addr = ptrtoint i8* %array to i32
     35   ret i32 %addr
     36 
     37 ; CHECK:      entry:
     38 ; CHECK-NEXT:   %array = alloca i8, i32 3
     39 ; CHECK-NEXT:   ret i32 %array
     40 }
     41 
     42 define internal i32 @AllocaA0Size4() {
     43 entry:
     44   %array = alloca i8, i32 4
     45   %addr = ptrtoint i8* %array to i32
     46   ret i32 %addr
     47 
     48 ; CHECK:      entry:
     49 ; CHECK-NEXT:   %array = alloca i8, i32 4
     50 ; CHECK-NEXT:   ret i32 %array
     51 }
     52 
     53 define internal i32 @AllocaA1Size4(i32 %n) {
     54 entry:
     55   %array = alloca i8, i32 4, align 1
     56   %addr = ptrtoint i8* %array to i32
     57   ret i32 %addr
     58 
     59 ; CHECK:      entry:
     60 ; CHECK-NEXT:   %array = alloca i8, i32 4, align 1
     61 ; CHECK-NEXT:   ret i32 %array
     62 }
     63 
     64 define internal i32 @AllocaA2Size4(i32 %n) {
     65 entry:
     66   %array = alloca i8, i32 4, align 2
     67   %addr = ptrtoint i8* %array to i32
     68   ret i32 %addr
     69 
     70 ; CHECK:      entry:
     71 ; CHECK-NEXT:   %array = alloca i8, i32 4, align 2
     72 ; CHECK-NEXT:   ret i32 %array
     73 }
     74 
     75 define internal i32 @AllocaA8Size4(i32 %n) {
     76 entry:
     77   %array = alloca i8, i32 4, align 8
     78   %addr = ptrtoint i8* %array to i32
     79   ret i32 %addr
     80 
     81 ; CHECK:      entry:
     82 ; CHECK-NEXT:   %array = alloca i8, i32 4, align 8
     83 ; CHECK-NEXT:   ret i32 %array
     84 }
     85 
     86 define internal i32 @Alloca16Size4(i32 %n) {
     87 entry:
     88   %array = alloca i8, i32 4, align 16
     89   %addr = ptrtoint i8* %array to i32
     90   ret i32 %addr
     91 
     92 ; CHECK:      entry:
     93 ; CHECK-NEXT:   %array = alloca i8, i32 4, align 16
     94 ; CHECK-NEXT:   ret i32 %array
     95 }
     96 
     97 ; Show examples where size is not known at compile time.
     98 
     99 define internal i32 @AllocaVarsizeA0(i32 %n) {
    100 entry:
    101   %array = alloca i8, i32 %n
    102   %addr = ptrtoint i8* %array to i32
    103   ret i32 %addr
    104 
    105 ; CHECK:      entry:
    106 ; CHECK-NEXT:   %array = alloca i8, i32 %n
    107 ; CHECK-NEXT:   ret i32 %array
    108 }
    109 
    110 define internal i32 @AllocaVarsizeA1(i32 %n) {
    111 entry:
    112   %array = alloca i8, i32 %n, align 1
    113   %addr = ptrtoint i8* %array to i32
    114   ret i32 %addr
    115 
    116 ; CHECK:      entry:
    117 ; CHECK-NEXT:   %array = alloca i8, i32 %n, align 1
    118 ; CHECK-NEXT:   ret i32 %array
    119 }
    120 
    121 define internal i32 @AllocaVarsizeA2(i32 %n) {
    122 entry:
    123   %array = alloca i8, i32 %n, align 2
    124   %addr = ptrtoint i8* %array to i32
    125   ret i32 %addr
    126 
    127 ; CHECK:      entry:
    128 ; CHECK-NEXT:   %array = alloca i8, i32 %n, align 2
    129 ; CHECK-NEXT:   ret i32 %array
    130 }
    131 
    132 define internal i32 @AllocaVarsizeA4(i32 %n) {
    133 entry:
    134   %array = alloca i8, i32 %n, align 4
    135   %addr = ptrtoint i8* %array to i32
    136   ret i32 %addr
    137 
    138 ; CHECK:      entry:
    139 ; CHECK-NEXT:   %array = alloca i8, i32 %n, align 4
    140 ; CHECK-NEXT:   ret i32 %array
    141 }
    142 
    143 define internal i32 @AllocaVarsizeA8(i32 %n) {
    144 entry:
    145   %array = alloca i8, i32 %n, align 8
    146   %addr = ptrtoint i8* %array to i32
    147   ret i32 %addr
    148 
    149 ; CHECK:      entry:
    150 ; CHECK-NEXT:   %array = alloca i8, i32 %n, align 8
    151 ; CHECK-NEXT:   ret i32 %array
    152 }
    153 
    154 define internal i32 @AllocaVarsizeA16(i32 %n) {
    155 entry:
    156   %array = alloca i8, i32 %n, align 16
    157   %addr = ptrtoint i8* %array to i32
    158   ret i32 %addr
    159 
    160 ; CHECK:      entry:
    161 ; CHECK-NEXT:   %array = alloca i8, i32 %n, align 16
    162 ; CHECK-NEXT:   ret i32 %array
    163 }
    164 
    165 ; NOIR: Total across all functions
    166