llvm.org GIT mirror llvm / 3f3e2c4
[WebAssembly] WebAssemblyFastISel getelementptr variable index support Summary: Previously -fast-isel getelementptr would constant-fold non-constant i8 load/stores. Reviewers: sunfish Subscribers: jfb, dschuff, sbc100, llvm-commits Differential Revision: https://reviews.llvm.org/D34044 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@306060 91177308-0d34-0410-b5e6-96231b3b80d8 Jacob Gravelle 3 years ago
2 changed file(s) with 119 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
6262 public:
6363 // Innocuous defaults for our address.
6464 Address() : Kind(RegBase), Offset(0), GV(0) { Base.Reg = 0; }
65 void setKind(BaseKind K) { Kind = K; }
65 void setKind(BaseKind K) {
66 assert(!isSet() && "Can't change kind with non-zero base");
67 Kind = K;
68 }
6669 BaseKind getKind() const { return Kind; }
6770 bool isRegBase() const { return Kind == RegBase; }
6871 bool isFIBase() const { return Kind == FrameIndexBase; }
6972 void setReg(unsigned Reg) {
7073 assert(isRegBase() && "Invalid base register access!");
74 assert(Base.Reg == 0 && "Overwriting non-zero register");
7175 Base.Reg = Reg;
7276 }
7377 unsigned getReg() const {
7680 }
7781 void setFI(unsigned FI) {
7882 assert(isFIBase() && "Invalid base frame index access!");
83 assert(Base.FI == 0 && "Overwriting non-zero frame index");
7984 Base.FI = FI;
8085 }
8186 unsigned getFI() const {
9095 int64_t getOffset() const { return Offset; }
9196 void setGlobalValue(const GlobalValue *G) { GV = G; }
9297 const GlobalValue *getGlobalValue() const { return GV; }
98 bool isSet() const {
99 if (isRegBase()) {
100 return Base.Reg != 0;
101 } else {
102 return Base.FI != 0;
103 }
104 }
93105 };
94106
95107 /// Keep a pointer to the WebAssemblySubtarget around so that we can make the
296308 DenseMap::iterator SI =
297309 FuncInfo.StaticAllocaMap.find(AI);
298310 if (SI != FuncInfo.StaticAllocaMap.end()) {
311 if (Addr.isSet()) {
312 return false;
313 }
299314 Addr.setKind(Address::FrameIndexBase);
300315 Addr.setFI(SI->second);
301316 return true;
339354 }
340355 break;
341356 }
357 }
358 if (Addr.isSet()) {
359 return false;
342360 }
343361 Addr.setReg(getRegForValue(Obj));
344362 return Addr.getReg() != 0;
0 ; RUN: llc < %s -asm-verbose=false -disable-wasm-explicit-locals -fast-isel -fast-isel-abort=1 | FileCheck %s
1
2 ; TODO: Merge this with offset.ll when fast-isel matches better.
3
4 target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
5 target triple = "wasm32-unknown-unknown-elf"
6
7 ; CHECK-LABEL: store_i8_with_variable_gep_offset:
8 ; CHECK: i32.add $push[[L0:[0-9]+]]=, $0, $1{{$}}
9 ; CHECK: i32.const $push[[L1:[0-9]+]]=, 0{{$}}
10 ; CHECK: i32.store8 0($pop[[L0]]), $pop[[L1]]{{$}}
11 define void @store_i8_with_variable_gep_offset(i8* %p, i32 %idx) {
12 %s = getelementptr inbounds i8, i8* %p, i32 %idx
13 store i8 0, i8* %s
14 ret void
15 }
16
17 ; CHECK-LABEL: store_i8_with_array_alloca_gep:
18 ; CHECK: i32.const $push[[L0:[0-9]+]]=, 0{{$}}
19 ; CHECK: i32.load $push[[L1:[0-9]+]]=, __stack_pointer($pop[[L0]]){{$}}
20 ; CHECK: i32.const $push[[L2:[0-9]+]]=, 32{{$}}
21 ; CHECK: i32.sub $push{{[0-9]+}}=, $pop[[L1]], $pop[[L2]]{{$}}
22 ; CHECK: i32.add $push[[L4:[0-9]+]]=, $pop{{[0-9]+}}, $0{{$}}
23 ; CHECK: i32.const $push[[L5:[0-9]+]]=, 0{{$}}
24 ; CHECK: i32.store8 0($pop[[L4]]), $pop[[L5]]{{$}}
25 define hidden void @store_i8_with_array_alloca_gep(i32 %idx) {
26 %A = alloca [30 x i8], align 16
27 %s = getelementptr inbounds [30 x i8], [30 x i8]* %A, i32 0, i32 %idx
28 store i8 0, i8* %s, align 1
29 ret void
30 }
31
32 ; CHECK-LABEL: store_i32_with_unfolded_gep_offset:
33 ; CHECK: i32.const $push[[L0:[0-9]+]]=, 24{{$}}
34 ; CHECK: i32.add $push[[L1:[0-9]+]]=, $0, $pop[[L0]]{{$}}
35 ; CHECK: i32.const $push[[L2:[0-9]+]]=, 0{{$}}
36 ; CHECK: i32.store 0($pop[[L1]]), $pop[[L2]]{{$}}
37 define void @store_i32_with_unfolded_gep_offset(i32* %p) {
38 %s = getelementptr i32, i32* %p, i32 6
39 store i32 0, i32* %s
40 ret void
41 }
42
43 ; CHECK-LABEL: store_i32_with_folded_gep_offset:
44 ; CHECK: i32.store 24($0), $pop{{[0-9]+$}}
45 define void @store_i32_with_folded_gep_offset(i32* %p) {
46 %s = getelementptr inbounds i32, i32* %p, i32 6
47 store i32 0, i32* %s
48 ret void
49 }
50
51 ; CHECK-LABEL: load_i32_with_folded_gep_offset:
52 ; CHECK: i32.load $push{{[0-9]+}}=, 24($0){{$}}
53 define i32 @load_i32_with_folded_gep_offset(i32* %p) {
54 %s = getelementptr inbounds i32, i32* %p, i32 6
55 %t = load i32, i32* %s
56 ret i32 %t
57 }
58
59 ; CHECK-LABEL: store_i64_with_unfolded_gep_offset:
60 ; CHECK: i32.const $push[[L0:[0-9]+]]=, 24{{$}}
61 ; CHECK: i32.add $push[[L1:[0-9]+]]=, $0, $pop[[L0]]{{$}}
62 ; CHECK: i64.const $push[[L2:[0-9]+]]=, 0{{$}}
63 ; CHECK: i64.store 0($pop[[L1]]), $pop[[L2]]{{$}}
64 define void @store_i64_with_unfolded_gep_offset(i64* %p) {
65 %s = getelementptr i64, i64* %p, i32 3
66 store i64 0, i64* %s
67 ret void
68 }
69
70 ; CHECK-LABEL: store_i8_with_folded_gep_offset:
71 ; CHECK: i32.store8 24($0), $pop{{[0-9]+$}}
72 define void @store_i8_with_folded_gep_offset(i8* %p) {
73 %s = getelementptr inbounds i8, i8* %p, i32 24
74 store i8 0, i8* %s
75 ret void
76 }
77
78 ; CHECK-LABEL: load_i8_u_with_folded_offset:
79 ; CHECK: i32.load8_u $push{{[0-9]+}}=, 24($0){{$}}
80 define i32 @load_i8_u_with_folded_offset(i8* %p) {
81 %q = ptrtoint i8* %p to i32
82 %r = add nuw i32 %q, 24
83 %s = inttoptr i32 %r to i8*
84 %t = load i8, i8* %s
85 %u = zext i8 %t to i32
86 ret i32 %u
87 }
88
89 ; TODO: this should be load8_s, need to fold sign-/zero-extend in fast-isel
90 ; CHECK-LABEL: load_i8_s_with_folded_offset:
91 ; CHECK: i32.load8_u $push{{[0-9]+}}=, 24($0){{$}}
92 define i32 @load_i8_s_with_folded_offset(i8* %p) {
93 %q = ptrtoint i8* %p to i32
94 %r = add nuw i32 %q, 24
95 %s = inttoptr i32 %r to i8*
96 %t = load i8, i8* %s
97 %u = sext i8 %t to i32
98 ret i32 %u
99 }