Skip to content

Commit 0a00fda

Browse files
author
badumbatish
committed
[WebAssembly] Fix nit from PR 145829
1 parent 3dfe71a commit 0a00fda

File tree

3 files changed

+20
-22
lines changed

3 files changed

+20
-22
lines changed

llvm/lib/Target/WebAssembly/WebAssemblyISelDAGToDAG.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -343,19 +343,19 @@ bool WebAssemblyDAGToDAGISel::SelectAddrAddOperands(MVT OffsetType, SDValue N,
343343
if (N.getOpcode() == ISD::ADD && !N.getNode()->getFlags().hasNoUnsignedWrap())
344344
return false;
345345

346-
// Folds constants in an add into the offset.
347346
for (size_t i = 0; i < 2; ++i) {
348347
SDValue Op = N.getOperand(i);
349348
SDValue OtherOp = N.getOperand(i == 0 ? 1 : 0);
350349

350+
// Folds constants in an add into the offset.
351351
if (ConstantSDNode *CN = dyn_cast<ConstantSDNode>(Op)) {
352352
Offset =
353353
CurDAG->getTargetConstant(CN->getZExtValue(), SDLoc(N), OffsetType);
354354
Addr = OtherOp;
355355
return true;
356356
}
357357

358-
// Fold Add of Global Address straight into load
358+
// Fold target global addresses into the offset.
359359
if (Op.getOpcode() == WebAssemblyISD::Wrapper)
360360
Op = Op.getOperand(0);
361361

llvm/test/CodeGen/WebAssembly/exception-legacy.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ define void @throw(ptr %p) {
3434
; CHECK: call foo
3535
; CHECK: catch $[[EXN:[0-9]+]]=, __cpp_exception
3636
; CHECK: global.set __stack_pointer
37-
; CHECK: i32.{{store|const}} {{.*}} 4
37+
; CHECK: i32.store __wasm_lpad_context
3838
; CHECK: call $drop=, _Unwind_CallPersonality, $[[EXN]]
3939
; CHECK: block
4040
; CHECK: br_if 0

llvm/test/CodeGen/WebAssembly/offset.ll

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -60,28 +60,26 @@ define i32 @load_i32_with_folded_gep_offset_nuw(ptr %p) {
6060
ret i32 %t
6161
}
6262

63-
@global_data = hidden local_unnamed_addr global [12 x i8] c"Hello world\00", align 1
64-
65-
define hidden signext i8 @global_load_i32_with_folded_gep_offset_nonconst_nuw(i32 noundef %idx) local_unnamed_addr {
66-
; CHECK-LABEL: global_load_i32_with_folded_gep_offset_nonconst_nuw:
67-
; CHECK: .functype global_load_i32_with_folded_gep_offset_nonconst_nuw (i32) -> (i32)
68-
; CHECK: i32.load8_s $push0=, global_data($0)
69-
; CHECK: return $pop0
70-
entry:
71-
%arrayidx = getelementptr inbounds nuw [12 x i8], ptr @global_data, i32 0, i32 %idx
72-
%0 = load i8, ptr %arrayidx, align 1
73-
ret i8 %0
63+
@global_data = external global i32
64+
65+
define i32 @load_i32_global_with_folded_gep_offset_nonconst_nuw(i32 %idx) {
66+
; CHECK-LABEL: load_i32_global_with_folded_gep_offset_nonconst_nuw:
67+
; CHECK: i32.const $push0=, 2
68+
; CHECK-NEXT: i32.shl $push1=, $0, $pop0
69+
; CHECK-NOT: i32.add
70+
; CHECK-NEXT: i32.load $push2=, global_data($pop1)
71+
%s = getelementptr nuw i32, ptr @global_data, i32 %idx
72+
%t = load i32, ptr %s
73+
ret i32 %t
7474
}
7575

76-
define hidden signext i8 @global_load_i32_with_folded_gep_offset_const_nuw() local_unnamed_addr {
77-
; CHECK-LABEL: global_load_i32_with_folded_gep_offset_const_nuw:
78-
; CHECK: .functype global_load_i32_with_folded_gep_offset_const_nuw () -> (i32)
79-
; CHECK: i32.const $push0=, 0
80-
; CHECK: i32.load8_s $push1=, global_data+2($pop0)
81-
; CHECK: return $pop1
76+
define i32 @load_i32_global_with_folded_gep_offset_const_nuw() {
77+
; CHECK-LABEL: load_i32_global_with_folded_gep_offset_const_nuw:
78+
; CHECK: i32.const $push0=, 8
79+
; CHECK-NEXT: i32.load $push1=, global_data($pop0)
8280
entry:
83-
%0 = load i8, ptr getelementptr inbounds nuw (i8, ptr @global_data, i32 2), align 1
84-
ret i8 %0
81+
%t = load i32, ptr getelementptr nuw (i32, ptr @global_data, i32 2)
82+
ret i32 %t
8583
}
8684

8785

0 commit comments

Comments
 (0)