1 ; Test for generation of jump table for ropi/rwpi 2 3 ; RUN: llc -relocation-model=static -mtriple=armv7a--none-eabi -disable-block-placement < %s | FileCheck %s --check-prefix=CHECK --check-prefix=ARM --check-prefix=ARM_ABS 4 ; RUN: llc -relocation-model=ropi -mtriple=armv7a--none-eabi -disable-block-placement < %s | FileCheck %s --check-prefix=CHECK --check-prefix=ARM --check-prefix=ARM_PC 5 ; RUN: llc -relocation-model=ropi-rwpi -mtriple=armv7a--none-eabi -disable-block-placement < %s | FileCheck %s --check-prefix=CHECK --check-prefix=ARM --check-prefix=ARM_PC 6 7 ; RUN: llc -relocation-model=static -mtriple=thumbv7m--none-eabi -disable-block-placement < %s | FileCheck %s --check-prefix=CHECK --check-prefix=THUMB2 8 ; RUN: llc -relocation-model=ropi -mtriple=thumbv7m--none-eabi -disable-block-placement < %s | FileCheck %s --check-prefix=CHECK --check-prefix=THUMB2 9 ; RUN: llc -relocation-model=ropi-rwpi -mtriple=thumbv7m--none-eabi -disable-block-placement < %s | FileCheck %s --check-prefix=CHECK --check-prefix=THUMB2 10 11 ; RUN: llc -relocation-model=static -mtriple=thumbv6m--none-eabi -disable-block-placement < %s | FileCheck %s --check-prefix=CHECK --check-prefix=THUMB1 12 ; RUN: llc -relocation-model=ropi -mtriple=thumbv6m--none-eabi -disable-block-placement < %s | FileCheck %s --check-prefix=CHECK --check-prefix=THUMB1 13 ; RUN: llc -relocation-model=ropi-rwpi -mtriple=thumbv6m--none-eabi -disable-block-placement < %s | FileCheck %s --check-prefix=CHECK --check-prefix=THUMB1 14 15 16 declare void @exit0() 17 declare void @exit1() 18 declare void @exit2() 19 declare void @exit3() 20 declare void @exit4() 21 define void @jump_table(i32 %val) { 22 entry: 23 switch i32 %val, label %default [ i32 1, label %lab1 24 i32 2, label %lab2 25 i32 3, label %lab3 26 i32 4, label %lab4 ] 27 28 default: 29 tail call void @exit0() 30 ret void 31 32 lab1: 33 tail call void @exit1() 34 ret void 35 36 lab2: 37 tail call void @exit2() 38 ret void 39 40 lab3: 41 tail call void @exit3() 42 ret void 43 44 lab4: 45 tail call void @exit4() 46 ret void 47 48 ; CHECK-LABEL: jump_table: 49 50 ; ARM: adr r[[R_TAB_BASE:[0-9]+]], [[LJTI:\.LJTI[0-9]+_[0-9]+]] 51 ; ARM_ABS: ldr pc, [r[[R_TAB_BASE]], r{{[0-9]+}}, lsl #2] 52 ; ARM_PC: ldr r[[R_OFFSET:[0-9]+]], [r[[R_TAB_BASE]], r{{[0-9]+}}, lsl #2] 53 ; ARM_PC: add pc, r[[R_TAB_BASE]], r[[R_OFFSET]] 54 ; ARM: [[LJTI]] 55 ; ARM_ABS: .long [[LBB1:\.LBB[0-9]+_[0-9]+]] 56 ; ARM_ABS: .long [[LBB2:\.LBB[0-9]+_[0-9]+]] 57 ; ARM_ABS: .long [[LBB3:\.LBB[0-9]+_[0-9]+]] 58 ; ARM_ABS: .long [[LBB4:\.LBB[0-9]+_[0-9]+]] 59 ; ARM_PC: .long [[LBB1:\.LBB[0-9]+_[0-9]+]]-[[LJTI]] 60 ; ARM_PC: .long [[LBB2:\.LBB[0-9]+_[0-9]+]]-[[LJTI]] 61 ; ARM_PC: .long [[LBB3:\.LBB[0-9]+_[0-9]+]]-[[LJTI]] 62 ; ARM_PC: .long [[LBB4:\.LBB[0-9]+_[0-9]+]]-[[LJTI]] 63 ; ARM: [[LBB1]] 64 ; ARM-NEXT: b exit1 65 ; ARM: [[LBB2]] 66 ; ARM-NEXT: b exit2 67 ; ARM: [[LBB3]] 68 ; ARM-NEXT: b exit3 69 ; ARM: [[LBB4]] 70 ; ARM-NEXT: b exit4 71 72 ; THUMB2: [[LCPI:\.LCPI[0-9]+_[0-9]+]]: 73 ; THUMB2: tbb [pc, r{{[0-9]+}}] 74 ; THUMB2: .byte ([[LBB1:\.LBB[0-9]+_[0-9]+]]-([[LCPI]]+4))/2 75 ; THUMB2: .byte ([[LBB2:\.LBB[0-9]+_[0-9]+]]-([[LCPI]]+4))/2 76 ; THUMB2: .byte ([[LBB3:\.LBB[0-9]+_[0-9]+]]-([[LCPI]]+4))/2 77 ; THUMB2: .byte ([[LBB4:\.LBB[0-9]+_[0-9]+]]-([[LCPI]]+4))/2 78 ; THUMB2: [[LBB1]] 79 ; THUMB2-NEXT: b exit1 80 ; THUMB2: [[LBB2]] 81 ; THUMB2-NEXT: b exit2 82 ; THUMB2: [[LBB3]] 83 ; THUMB2-NEXT: b exit3 84 ; THUMB2: [[LBB4]] 85 ; THUMB2-NEXT: b exit4 86 87 ; THUMB1: .p2align 2 88 ; THUMB1: add r[[x:[0-9]+]], pc 89 ; THUMB1: ldrb r[[x]], [r[[x]], #4] 90 ; THUMB1: lsls r[[x]], r[[x]], #1 91 ; THUMB1: [[LCPI:\.LCPI[0-9]+_[0-9]+]]: 92 ; THUMB1: add pc, r[[x]] 93 ; THUMB1: .p2align 2 94 ; THUMB1: .byte ([[LBB1:\.LBB[0-9]+_[0-9]+]]-([[LCPI]]+4))/2 95 ; THUMB1: .byte ([[LBB2:\.LBB[0-9]+_[0-9]+]]-([[LCPI]]+4))/2 96 ; THUMB1: .byte ([[LBB3:\.LBB[0-9]+_[0-9]+]]-([[LCPI]]+4))/2 97 ; THUMB1: .byte ([[LBB4:\.LBB[0-9]+_[0-9]+]]-([[LCPI]]+4))/2 98 ; THUMB1: [[LBB1]] 99 ; THUMB1-NEXT: bl exit1 100 ; THUMB1: [[LBB2]] 101 ; THUMB1-NEXT: bl exit2 102 ; THUMB1: [[LBB3]] 103 ; THUMB1-NEXT: bl exit3 104 ; THUMB1: [[LBB4]] 105 ; THUMB1-NEXT: bl exit4 106 } 107