1# RUN: llc -mtriple=aarch64-linux-gnu %s -run-pass=aarch64-jump-tables -o - | FileCheck %s 2--- | 3 define i32 @test_jumptable(i32 %in) { 4 unreachable 5 } 6 7 define void @test_inline_asm_no_compress() { ret void } 8 define void @test_bb_alignment_not_byte_compressable() { ret void } 9 10... 11--- 12name: test_jumptable 13alignment: 4 14exposesReturnsTwice: false 15legalized: false 16regBankSelected: false 17selected: false 18tracksRegLiveness: true 19liveins: 20 - { reg: '$w0' } 21frameInfo: 22 isFrameAddressTaken: false 23 isReturnAddressTaken: false 24 hasStackMap: false 25 hasPatchPoint: false 26 stackSize: 0 27 offsetAdjustment: 0 28 maxAlignment: 0 29 adjustsStack: false 30 hasCalls: false 31 maxCallFrameSize: 0 32 hasOpaqueSPAdjustment: false 33 hasVAStart: false 34 hasMustTailInVarArgFunc: false 35jumpTable: 36 kind: block-address 37 entries: 38 - id: 0 39 blocks: [ '%bb.2', '%bb.3' ] 40 - id: 1 41 blocks: [ '%bb.4', '%bb.5' ] 42 - id: 2 43 blocks: [ '%bb.7' ] 44 - id: 3 45 blocks: [ '%bb.9' ] 46 - id: 4 47 blocks: [ '%bb.9' ] 48 - id: 5 49 blocks: [ '%bb.11' ] 50body: | 51 bb.0 (%ir-block.0): 52 liveins: $x8 53 54 bb.1 (%ir-block.0): 55 ; CHECK-LABEL: body: 56 ; CHECK-LABEL: bb.1 57 ; CHECK: JumpTableDest8 58 liveins: $x8 59 early-clobber $x10, dead early-clobber $x11 = JumpTableDest32 undef killed $x9, undef killed $x8, %jump-table.0 60 BR killed $x10 61 62 bb.2: 63 ; Last destination is 4 * 255 = 1020 bytes after first. Byte is OK. 64 dead $xzr = SPACE 1020, undef $xzr 65 66 bb.3: 67 ; CHECK-LABEL: bb.3 68 ; CHECK: JumpTableDest16 69 early-clobber $x10, dead early-clobber $x11 = JumpTableDest32 undef killed $x9, undef killed $x8, %jump-table.1 70 BR killed $x10 71 72 bb.4: 73 ; Last destination is 4 * 256 = 1024 bytes after first. Half needed. 74 dead $xzr = SPACE 1024, undef $xzr 75 76 bb.5: 77 ; CHECK-LABEL: bb.5 78 ; CHECK: JumpTableDest8 79 early-clobber $x10, dead early-clobber $x11 = JumpTableDest32 undef killed $x9, undef killed $x8, %jump-table.2 80 BR killed $x10 81 82 bb.6: 83 ; First destination is (2^20 - 4) after reference. Just reachable by ADR so can use compressed table. 84 dead $xzr = SPACE 1048556, undef $xzr 85 86 bb.7: 87 ; CHECK-LABEL: bb.7 88 ; CHECK: JumpTableDest32 89 early-clobber $x10, dead early-clobber $x11 = JumpTableDest32 undef killed $x9, undef killed $x8, %jump-table.3 90 BR killed $x10 91 92 bb.8: 93 ; First destination is 2^20 after reference. Compressed table cannot reach it. 94 dead $xzr = SPACE 1048560, undef $xzr 95 96 bb.9: 97 ; First destination is 2^20 before reference. Just within reach of ADR. 98 dead $xzr = SPACE 1048576, undef $xzr 99 100 bb.10: 101 ; CHECK-LABEL: bb.10 102 ; CHECK: JumpTableDest8 103 early-clobber $x10, dead early-clobber $x11 = JumpTableDest32 undef killed $x9, undef killed $x8, %jump-table.4 104 BR killed $x10 105 106 bb.11: 107 ; First destination is 2^20 before reference. Just within reach of ADR. 108 dead $xzr = SPACE 1048580, undef $xzr 109 110 bb.12: 111 ; CHECK-LABEL: bb.12 112 ; CHECK: JumpTableDest32 113 early-clobber $x10, dead early-clobber $x11 = JumpTableDest32 undef killed $x9, undef killed $x8, %jump-table.5 114 BR killed $x10 115... 116--- 117name: test_inline_asm_no_compress 118alignment: 4 119tracksRegLiveness: true 120liveins: 121 - { reg: '$w0' } 122 - { reg: '$w1' } 123 - { reg: '$w2' } 124frameInfo: 125 maxAlignment: 1 126 maxCallFrameSize: 0 127machineFunctionInfo: 128 hasRedZone: false 129jumpTable: 130 kind: label-difference32 131 entries: 132 - id: 0 133 blocks: [ '%bb.2', '%bb.4', '%bb.5', '%bb.6', '%bb.7', '%bb.8' ] 134body: | 135 bb.0: 136 successors: %bb.3(0x12492492), %bb.1(0x6db6db6e) 137 liveins: $w0, $w1, $w2 138 139 dead $wzr = SUBSWri renamable $w0, 5, 0, implicit-def $nzcv 140 Bcc 8, %bb.3, implicit $nzcv 141 142 bb.1: 143 successors: %bb.2, %bb.4, %bb.5, %bb.6, %bb.7, %bb.8 144 liveins: $w0, $w1, $w2 145 ; We check that if there's an inline asm instruction in the jump table, 146 ; that we skip compression. This is due to not being able to rely on 147 ; finding the instruction size in some cases. 148 ; CHECK-LABEL: test_inline_asm_no_compress 149 ; CHECK-LABEL: bb.1 150 ; CHECK: JumpTableDest32 151 renamable $w8 = ORRWrs $wzr, killed renamable $w0, 0, implicit-def $x8 152 $x9 = ADRP target-flags(aarch64-page) %jump-table.0 153 renamable $x9 = ADDXri $x9, target-flags(aarch64-pageoff, aarch64-nc) %jump-table.0, 0 154 early-clobber renamable $x10, dead early-clobber renamable $x11 = JumpTableDest32 killed renamable $x9, killed renamable $x8, %jump-table.0 155 BR killed renamable $x10 156 157 bb.2: 158 liveins: $w1, $w2 159 160 INLINEASM &".byte 0x1f,0x20,0x03,0xd5,0x1f,0x20,0x03,0xd5\0A\09.byte 0x1f,0x20,0x03,0xd5,0x1f,0x20,0x03,0xd5\0A\09.byte 0x1f,0x20,0x03,0xd5,0x1f,0x20,0x03,0xd5\0A\09.byte 0x1f,0x20,0x03,0xd5,0x1f,0x20,0x03,0xd5\0A\09.byte 0x1f,0x20,0x03,0xd5,0x1f,0x20,0x03,0xd5\0A\09.byte 0x1f,0x20,0x03,0xd5,0x1f,0x20,0x03,0xd5\0A\09.byte 0x1f,0x20,0x03,0xd5,0x1f,0x20,0x03,0xd5\0A\09.byte 0x1f,0x20,0x03,0xd5,0x1f,0x20,0x03,0xd5\0A\09.byte 0x1f,0x20,0x03,0xd5,0x1f,0x20,0x03,0xd5\0A\09.byte 0x1f,0x20,0x03,0xd5,0x1f,0x20,0x03,0xd5\0A\09.byte 0x1f,0x20,0x03,0xd5,0x1f,0x20,0x03,0xd5\0A\09.byte 0x1f,0x20,0x03,0xd5,0x1f,0x20,0x03,0xd5\0A\09.byte 0x1f,0x20,0x03,0xd5,0x1f,0x20,0x03,0xd5\0A\09.byte 0x1f,0x20,0x03,0xd5,0x1f,0x20,0x03,0xd5\0A\09.byte 0x1f,0x20,0x03,0xd5,0x1f,0x20,0x03,0xd5\0A\09.byte 0x1f,0x20,0x03,0xd5,0x1f,0x20,0x03,0xd5\0A\09.byte 0x1f,0x20,0x03,0xd5,0x1f,0x20,0x03,0xd5\0A\09.byte 0x1f,0x20,0x03,0xd5,0x1f,0x20,0x03,0xd5\0A\09.byte 0x1f,0x20,0x03,0xd5,0x1f,0x20,0x03,0xd5\0A\09.byte 0x1f,0x20,0x03,0xd5,0x1f,0x20,0x03,0xd5\0A\09.byte 0x1f,0x20,0x03,0xd5,0x1f,0x20,0x03,0xd5\0A\09.byte 0x1f,0x20,0x03,0xd5,0x1f,0x20,0x03,0xd5\0A\09.byte 0x1f,0x20,0x03,0xd5,0x1f,0x20,0x03,0xd5\0A\09.byte 0x1f,0x20,0x03,0xd5,0x1f,0x20,0x03,0xd5\0A\09.byte 0x1f,0x20,0x03,0xd5,0x1f,0x20,0x03,0xd5\0A\09.byte 0x1f,0x20,0x03,0xd5,0x1f,0x20,0x03,0xd5\0A\09.byte 0x1f,0x20,0x03,0xd5,0x1f,0x20,0x03,0xd5\0A\09.byte 0x1f,0x20,0x03,0xd5,0x1f,0x20,0x03,0xd5\0A\09.byte 0x1f,0x20,0x03,0xd5,0x1f,0x20,0x03,0xd5\0A\09.byte 0x1f,0x20,0x03,0xd5,0x1f,0x20,0x03,0xd5\0A\09.byte 0x1f,0x20,0x03,0xd5,0x1f,0x20,0x03,0xd5\0A\09.byte 0x1f,0x20,0x03,0xd5,0x1f,0x20,0x03,0xd5\0A\09.byte 0x1f,0x20,0x03,0xd5,0x1f,0x20,0x03,0xd5\0A\09.byte 0x1f,0x20,0x03,0xd5,0x1f,0x20,0x03,0xd5\0A\09.byte 0x1f,0x20,0x03,0xd5,0x1f,0x20,0x03,0xd5\0A\09.byte 0x1f,0x20,0x03,0xd5,0x1f,0x20,0x03,0xd5\0A\09.byte 0x1f,0x20,0x03,0xd5,0x1f,0x20,0x03,0xd5\0A\09.byte 0x1f,0x20,0x03,0xd5,0x1f,0x20,0x03,0xd5\0A\09.byte 0x1f,0x20,0x03,0xd5,0x1f,0x20,0x03,0xd5\0A\09.byte 0x1f,0x20,0x03,0xd5,0x1f,0x20,0x03,0xd5\0A\09.byte 0x1f,0x20,0x03,0xd5,0x1f,0x20,0x03,0xd5\0A\09.byte 0x1f,0x20,0x03,0xd5,0x1f,0x20,0x03,0xd5\0A\09.byte 0x1f,0x20,0x03,0xd5,0x1f,0x20,0x03,0xd5\0A\09.byte 0x1f,0x20,0x03,0xd5,0x1f,0x20,0x03,0xd5\0A\09.byte 0x1f,0x20,0x03,0xd5,0x1f,0x20,0x03,0xd5\0A\09.byte 0x1f,0x20,0x03,0xd5,0x1f,0x20,0x03,0xd5\0A\09.byte 0x1f,0x20,0x03,0xd5,0x1f,0x20,0x03,0xd5\0A\09.byte 0x1f,0x20,0x03,0xd5,0x1f,0x20,0x03,0xd5\0A\09.byte 0x1f,0x20,0x03,0xd5,0x1f,0x20,0x03,0xd5\0A\09.byte 0x1f,0x20,0x03,0xd5,0x1f,0x20,0x03,0xd5\0A\09.byte 0x1f,0x20,0x03,0xd5,0x1f,0x20,0x03,0xd5\0A\09.byte 0x1f,0x20,0x03,0xd5,0x1f,0x20,0x03,0xd5\0A\09.byte 0x1f,0x20,0x03,0xd5,0x1f,0x20,0x03,0xd5\0A\09.byte 0x1f,0x20,0x03,0xd5,0x1f,0x20,0x03,0xd5\0A\09.byte 0x1f,0x20,0x03,0xd5,0x1f,0x20,0x03,0xd5\0A\09.byte 0x1f,0x20,0x03,0xd5,0x1f,0x20,0x03,0xd5\0A\09.byte 0x1f,0x20,0x03,0xd5,0x1f,0x20,0x03,0xd5\0A\09.byte 0x1f,0x20,0x03,0xd5,0x1f,0x20,0x03,0xd5\0A\09.byte 0x1f,0x20,0x03,0xd5,0x1f,0x20,0x03,0xd5\0A\09.byte 0x1f,0x20,0x03,0xd5,0x1f,0x20,0x03,0xd5\0A\09.byte 0x1f,0x20,0x03,0xd5,0x1f,0x20,0x03,0xd5\0A\09.byte 0x1f,0x20,0x03,0xd5,0x1f,0x20,0x03,0xd5\0A\09.byte 0x1f,0x20,0x03,0xd5,0x1f,0x20,0x03,0xd5\0A\09.byte 0x1f,0x20,0x03,0xd5,0x1f,0x20,0x03,0xd5\0A\09", 1 /* sideeffect attdialect */ 161 INLINEASM &".byte 0x1f,0x20,0x03,0xd5,0x1f,0x20,0x03,0xd5\0A\09.byte 0x1f,0x20,0x03,0xd5,0x1f,0x20,0x03,0xd5\0A\09.byte 0x1f,0x20,0x03,0xd5,0x1f,0x20,0x03,0xd5\0A\09.byte 0x1f,0x20,0x03,0xd5,0x1f,0x20,0x03,0xd5\0A\09.byte 0x1f,0x20,0x03,0xd5,0x1f,0x20,0x03,0xd5\0A\09.byte 0x1f,0x20,0x03,0xd5,0x1f,0x20,0x03,0xd5\0A\09.byte 0x1f,0x20,0x03,0xd5,0x1f,0x20,0x03,0xd5\0A\09.byte 0x1f,0x20,0x03,0xd5,0x1f,0x20,0x03,0xd5\0A\09.byte 0x1f,0x20,0x03,0xd5,0x1f,0x20,0x03,0xd5\0A\09.byte 0x1f,0x20,0x03,0xd5,0x1f,0x20,0x03,0xd5\0A\09.byte 0x1f,0x20,0x03,0xd5,0x1f,0x20,0x03,0xd5\0A\09.byte 0x1f,0x20,0x03,0xd5,0x1f,0x20,0x03,0xd5\0A\09.byte 0x1f,0x20,0x03,0xd5,0x1f,0x20,0x03,0xd5\0A\09.byte 0x1f,0x20,0x03,0xd5,0x1f,0x20,0x03,0xd5\0A\09.byte 0x1f,0x20,0x03,0xd5,0x1f,0x20,0x03,0xd5\0A\09.byte 0x1f,0x20,0x03,0xd5,0x1f,0x20,0x03,0xd5\0A\09.byte 0x1f,0x20,0x03,0xd5,0x1f,0x20,0x03,0xd5\0A\09.byte 0x1f,0x20,0x03,0xd5,0x1f,0x20,0x03,0xd5\0A\09.byte 0x1f,0x20,0x03,0xd5,0x1f,0x20,0x03,0xd5\0A\09.byte 0x1f,0x20,0x03,0xd5,0x1f,0x20,0x03,0xd5\0A\09.byte 0x1f,0x20,0x03,0xd5,0x1f,0x20,0x03,0xd5\0A\09.byte 0x1f,0x20,0x03,0xd5,0x1f,0x20,0x03,0xd5\0A\09.byte 0x1f,0x20,0x03,0xd5,0x1f,0x20,0x03,0xd5\0A\09.byte 0x1f,0x20,0x03,0xd5,0x1f,0x20,0x03,0xd5\0A\09.byte 0x1f,0x20,0x03,0xd5,0x1f,0x20,0x03,0xd5\0A\09.byte 0x1f,0x20,0x03,0xd5,0x1f,0x20,0x03,0xd5\0A\09.byte 0x1f,0x20,0x03,0xd5,0x1f,0x20,0x03,0xd5\0A\09.byte 0x1f,0x20,0x03,0xd5,0x1f,0x20,0x03,0xd5\0A\09.byte 0x1f,0x20,0x03,0xd5,0x1f,0x20,0x03,0xd5\0A\09.byte 0x1f,0x20,0x03,0xd5,0x1f,0x20,0x03,0xd5\0A\09.byte 0x1f,0x20,0x03,0xd5,0x1f,0x20,0x03,0xd5\0A\09.byte 0x1f,0x20,0x03,0xd5,0x1f,0x20,0x03,0xd5\0A\09.byte 0x1f,0x20,0x03,0xd5,0x1f,0x20,0x03,0xd5\0A\09.byte 0x1f,0x20,0x03,0xd5,0x1f,0x20,0x03,0xd5\0A\09.byte 0x1f,0x20,0x03,0xd5,0x1f,0x20,0x03,0xd5\0A\09.byte 0x1f,0x20,0x03,0xd5,0x1f,0x20,0x03,0xd5\0A\09.byte 0x1f,0x20,0x03,0xd5,0x1f,0x20,0x03,0xd5\0A\09.byte 0x1f,0x20,0x03,0xd5,0x1f,0x20,0x03,0xd5\0A\09.byte 0x1f,0x20,0x03,0xd5,0x1f,0x20,0x03,0xd5\0A\09.byte 0x1f,0x20,0x03,0xd5,0x1f,0x20,0x03,0xd5\0A\09.byte 0x1f,0x20,0x03,0xd5,0x1f,0x20,0x03,0xd5\0A\09.byte 0x1f,0x20,0x03,0xd5,0x1f,0x20,0x03,0xd5\0A\09.byte 0x1f,0x20,0x03,0xd5,0x1f,0x20,0x03,0xd5\0A\09.byte 0x1f,0x20,0x03,0xd5,0x1f,0x20,0x03,0xd5\0A\09.byte 0x1f,0x20,0x03,0xd5,0x1f,0x20,0x03,0xd5\0A\09.byte 0x1f,0x20,0x03,0xd5,0x1f,0x20,0x03,0xd5\0A\09.byte 0x1f,0x20,0x03,0xd5,0x1f,0x20,0x03,0xd5\0A\09.byte 0x1f,0x20,0x03,0xd5,0x1f,0x20,0x03,0xd5\0A\09.byte 0x1f,0x20,0x03,0xd5,0x1f,0x20,0x03,0xd5\0A\09.byte 0x1f,0x20,0x03,0xd5,0x1f,0x20,0x03,0xd5\0A\09.byte 0x1f,0x20,0x03,0xd5,0x1f,0x20,0x03,0xd5\0A\09.byte 0x1f,0x20,0x03,0xd5,0x1f,0x20,0x03,0xd5\0A\09.byte 0x1f,0x20,0x03,0xd5,0x1f,0x20,0x03,0xd5\0A\09.byte 0x1f,0x20,0x03,0xd5,0x1f,0x20,0x03,0xd5\0A\09.byte 0x1f,0x20,0x03,0xd5,0x1f,0x20,0x03,0xd5\0A\09.byte 0x1f,0x20,0x03,0xd5,0x1f,0x20,0x03,0xd5\0A\09.byte 0x1f,0x20,0x03,0xd5,0x1f,0x20,0x03,0xd5\0A\09.byte 0x1f,0x20,0x03,0xd5,0x1f,0x20,0x03,0xd5\0A\09.byte 0x1f,0x20,0x03,0xd5,0x1f,0x20,0x03,0xd5\0A\09.byte 0x1f,0x20,0x03,0xd5,0x1f,0x20,0x03,0xd5\0A\09.byte 0x1f,0x20,0x03,0xd5,0x1f,0x20,0x03,0xd5\0A\09.byte 0x1f,0x20,0x03,0xd5,0x1f,0x20,0x03,0xd5\0A\09.byte 0x1f,0x20,0x03,0xd5,0x1f,0x20,0x03,0xd5\0A\09.byte 0x1f,0x20,0x03,0xd5,0x1f,0x20,0x03,0xd5\0A\09", 1 /* sideeffect attdialect */ 162 $w0 = ADDWrs killed renamable $w2, killed renamable $w1, 0 163 RET undef $lr, implicit $w0 164 165 bb.3: 166 $w0 = MOVZWi 0, 0 167 RET undef $lr, implicit $w0 168 169 bb.4: 170 liveins: $w1, $w2 171 172 renamable $w0 = nsw MADDWrrr killed renamable $w2, killed renamable $w1, $wzr 173 RET undef $lr, implicit $w0 174 175 bb.5: 176 liveins: $w1, $w2 177 178 $w0 = SUBWrs killed renamable $w1, killed renamable $w2, 0 179 RET undef $lr, implicit $w0 180 181 bb.6: 182 liveins: $w1, $w2 183 184 $w0 = SUBWrs killed renamable $w2, killed renamable $w1, 0 185 RET undef $lr, implicit $w0 186 187 bb.7: 188 liveins: $w1, $w2 189 190 renamable $w0 = MADDWrrr killed renamable $w1, renamable $w1, killed renamable $w2 191 RET undef $lr, implicit $w0 192 193 bb.8: 194 liveins: $w1, $w2 195 196 renamable $w8 = nsw MADDWrrr renamable $w2, renamable $w2, $wzr 197 renamable $w0 = MADDWrrr killed renamable $w8, killed renamable $w2, killed renamable $w1 198 RET undef $lr, implicit $w0 199 200... 201--- 202name: test_bb_alignment_not_byte_compressable 203alignment: 4 204tracksRegLiveness: true 205liveins: 206 - { reg: '$w0' } 207 - { reg: '$w1' } 208 - { reg: '$w2' } 209frameInfo: 210 maxAlignment: 1 211 maxCallFrameSize: 0 212machineFunctionInfo: 213 hasRedZone: false 214jumpTable: 215 kind: label-difference32 216 entries: 217 - id: 0 218 blocks: [ '%bb.2', '%bb.4', '%bb.5', '%bb.6', '%bb.7', '%bb.8' ] 219body: | 220 bb.0: 221 successors: %bb.3(0x12492492), %bb.1(0x6db6db6e) 222 liveins: $w0, $w1, $w2 223 224 dead $wzr = SUBSWri renamable $w0, 5, 0, implicit-def $nzcv 225 Bcc 8, %bb.3, implicit $nzcv 226 227 bb.1: 228 successors: %bb.2, %bb.4, %bb.5, %bb.6, %bb.7, %bb.8 229 liveins: $w0, $w1, $w2 230 ; Ensure there's no jump table compression when block alignments are bigger 231 ; than the function alignment because we don't known the padding length at 232 ; the point where compression is done. 233 ; CHECK-LABEL: test_bb_alignment_not_byte_compressable 234 ; CHECK-LABEL: bb.1 235 ; CHECK: JumpTableDest16 236 renamable $w8 = ORRWrs $wzr, killed renamable $w0, 0, implicit-def $x8 237 $x9 = ADRP target-flags(aarch64-page) %jump-table.0 238 renamable $x9 = ADDXri $x9, target-flags(aarch64-pageoff, aarch64-nc) %jump-table.0, 0 239 early-clobber renamable $x10, dead early-clobber renamable $x11 = JumpTableDest32 killed renamable $x9, killed renamable $x8, %jump-table.0 240 BR killed renamable $x10 241 242 bb.2: 243 liveins: $w1, $w2 244 $w0 = ADDWrs killed renamable $w2, killed renamable $w1, 0 245 RET undef $lr, implicit $w0 246 247 bb.3: 248 $w0 = MOVZWi 0, 0 249 RET undef $lr, implicit $w0 250 251 bb.4: 252 liveins: $w1, $w2 253 254 renamable $w0 = nsw MADDWrrr killed renamable $w2, killed renamable $w1, $wzr 255 RET undef $lr, implicit $w0 256 257 ; bb.5 is aligned to make it more that 256 instructions away from bb.1, which 258 ; means we can no longer assume the jump table will be byte indexable. 259 bb.5 (align 1024): 260 liveins: $w1, $w2 261 262 $w0 = SUBWrs killed renamable $w1, killed renamable $w2, 0 263 RET undef $lr, implicit $w0 264 265 bb.6: 266 liveins: $w1, $w2 267 268 $w0 = SUBWrs killed renamable $w2, killed renamable $w1, 0 269 RET undef $lr, implicit $w0 270 271 bb.7: 272 liveins: $w1, $w2 273 274 renamable $w0 = MADDWrrr killed renamable $w1, renamable $w1, killed renamable $w2 275 RET undef $lr, implicit $w0 276 277 bb.8: 278 liveins: $w1, $w2 279 280 renamable $w8 = nsw MADDWrrr renamable $w2, renamable $w2, $wzr 281 renamable $w0 = MADDWrrr killed renamable $w8, killed renamable $w2, killed renamable $w1 282 RET undef $lr, implicit $w0 283 284... 285