Home | History | Annotate | Download | only in Thumb
      1 ; REQUIRES: asserts
      2 ; RUN: llc < %s -debug-only=codegenprepare -o /dev/null 2>&1 | FileCheck %s
      3 
      4 ; These are regression tests for
      5 ;  https://bugs.llvm.org/show_bug.cgi?id=34106
      6 ;    "ARMTargetLowering::isLegalAddressingMode can accept incorrect
      7 ;    addressing modes for Thumb1 target"
      8 ;
      9 ; The Thumb1 target addressing modes don't support scaling.
     10 ; It supports: r1 + r2, where r1 and r2 can be the same register.
     11 
     12 target datalayout = "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64"
     13 target triple = "thumbv6m-arm-none-eabi"
     14 
     15 ; Test case 01: %n is scaled by 4 (size of i32).
     16 ; Expected: GEP cannot be folded into LOAD.
     17 ; CHECK: local addrmode: [Base:%arrayidx]
     18 define i32 @load01(i32* %p, i32 %n) nounwind {
     19 entry:
     20   %arrayidx = getelementptr inbounds i32, i32* %p, i32 %n
     21   %0 = load i32, i32* %arrayidx, align 4
     22   ret i32 %0
     23 }
     24 
     25 ; Test case 02: No scale of %n is needed because the size of i8 is 1.
     26 ; Expected: GEP can be folded into LOAD.
     27 ; CHECK: local addrmode: [Base:%p + 1*%n]
     28 define i8 @load02(i8* %p, i32 %n) nounwind {
     29 entry:
     30   %arrayidx = getelementptr inbounds i8, i8* %p, i32 %n
     31   %0 = load i8, i8* %arrayidx
     32   ret i8 %0
     33 }
     34 
     35 ; Test case 03: 2*%x can be represented as %x + %x.
     36 ; Expected: GEP can be folded into LOAD.
     37 ; CHECK: local addrmode: [2*%x]
     38 define i32 @load03(i32 %x) nounwind {
     39 entry:
     40   %mul = shl nsw i32 %x, 1
     41   %0 = inttoptr i32 %mul to i32*
     42   %1 = load i32, i32* %0, align 4
     43   ret i32 %1
     44 }
     45 
     46