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
; RUN: llc < %s -mtriple=armv7a-eabi   | FileCheck %s -check-prefix=CHECK -check-prefix=CHECK-AT2
; RUN: llc < %s -mtriple=thumbv7m-eabi | FileCheck %s -check-prefix=CHECK -check-prefix=CHECK-AT2
; RUN: llc < %s -mtriple=thumbv6m-eabi | FileCheck %s -check-prefix=CHECK -check-prefix=CHECK-T1

; This test checks that various kinds of getelementptr are all optimised to a
; simple multiply plus add, with the add being done by a register offset if the
; result is used in a load.

; CHECK-LABEL: calc_1d:
; CHECK: mov{{s?}} [[REG1:r[0-9]+]], #84
; CHECK-AT2: mla r0, r1, [[REG1]], r0
; CHECK-T1: muls [[REG2:r[0-9]+]], r1, [[REG1]]
; CHECK-T1: adds r0, r0, [[REG2]]
define i32* @calc_1d(i32* %p, i32 %n) {
entry:
  %mul = mul nsw i32 %n, 21
  %add.ptr = getelementptr inbounds i32, i32* %p, i32 %mul
  ret i32* %add.ptr
}

; CHECK-LABEL: load_1d:
; CHECK: mov{{s?}} [[REG1:r[0-9]+]], #84
; CHECK: mul{{s?}} [[REG2:r[0-9]+]],{{( r1,)?}} [[REG1]]{{(, r1)?}}
; CHECK: ldr r0, [r0, [[REG2]]]
define i32 @load_1d(i32* %p, i32 %n) #1 {
entry:
  %mul = mul nsw i32 %n, 21
  %arrayidx = getelementptr inbounds i32, i32* %p, i32 %mul
  %0 = load i32, i32* %arrayidx, align 4
  ret i32 %0
}

; CHECK-LABEL: calc_2d_a:
; CHECK: mov{{s?}} [[REG1:r[0-9]+]], #84
; CHECK-AT2: mla r0, r1, [[REG1]], r0
; CHECK-T1: muls [[REG2:r[0-9]+]], r1, [[REG1]]
; CHECK-T1: adds r0, r0, [[REG2]]
define i32* @calc_2d_a([100 x i32]* %p, i32 %n) {
entry:
  %mul = mul nsw i32 %n, 21
  %arrayidx1 = getelementptr inbounds [100 x i32], [100 x i32]* %p, i32 0, i32 %mul
  ret i32* %arrayidx1
}

; CHECK-LABEL: load_2d_a:
; CHECK: mov{{s?}} [[REG1:r[0-9]+]], #84
; CHECK: mul{{s?}} [[REG2:r[0-9]+]],{{( r1,)?}} [[REG1]]{{(, r1)?}}
; CHECK: ldr r0, [r0, [[REG2]]]
define i32 @load_2d_a([100 x i32]* %p, i32 %n) #1 {
entry:
  %mul = mul nsw i32 %n, 21
  %arrayidx1 = getelementptr inbounds [100 x i32], [100 x i32]* %p, i32 0, i32 %mul
  %0 = load i32, i32* %arrayidx1, align 4
  ret i32 %0
}

; CHECK-LABEL: calc_2d_b:
; CHECK: mov{{s?}} [[REG1:r[0-9]+]], #84
; CHECK-AT2: mla r0, r1, [[REG1]], r0
; CHECK-T1: muls [[REG2:r[0-9]+]], r1, [[REG1]]
; CHECK-T1: adds r0, r0, [[REG2]]
define i32* @calc_2d_b([21 x i32]* %p, i32 %n) {
entry:
  %arrayidx1 = getelementptr inbounds [21 x i32], [21 x i32]* %p, i32 %n, i32 0
  ret i32* %arrayidx1
}

; CHECK-LABEL: load_2d_b:
; CHECK: mov{{s?}} [[REG1:r[0-9]+]], #84
; CHECK: mul{{s?}} [[REG2:r[0-9]+]],{{( r1,)?}} [[REG1]]{{(, r1)?}}
; CHECK: ldr r0, [r0, [[REG2]]]
define i32 @load_2d_b([21 x i32]* %p, i32 %n) {
entry:
  %arrayidx1 = getelementptr inbounds [21 x i32], [21 x i32]* %p, i32 %n, i32 0
  %0 = load i32, i32* %arrayidx1, align 4
  ret i32 %0
}