<commit_before>; RUN: llc < %s -asm-verbose=false | FileCheck %s

; Test that constant offsets can be folded into global addresses.

target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
target triple = "wasm32-unknown-unknown"

@x = external global [0 x i32]
@y = global [50 x i32] zeroinitializer

; Test basic constant offsets of both defined and external symbols.

; CHECK-LABEL: test0:
; CHECK-NEXT: .result i32{{$}}
; CHECK-NEXT: i32.const $push0=, x+188{{$}}
; CHECK=NEXT: return $pop0{{$}}
define i32* @test0() {
  ret i32* getelementptr ([0 x i32], [0 x i32]* @x, i32 0, i32 47)
}

; CHECK-LABEL: test1:
; CHECK-NEXT: .result i32{{$}}
; CHECK-NEXT: i32.const $push0=, y+188{{$}}
; CHECK=NEXT: return $pop0{{$}}
define i32* @test1() {
  ret i32* getelementptr ([50 x i32], [50 x i32]* @y, i32 0, i32 47)
}

; Test zero offsets.

; CHECK-LABEL: test2:
; CHECK-NEXT: .result i32{{$}}
; CHECK-NEXT: i32.const $push0=, x{{$}}
; CHECK=NEXT: return $pop0{{$}}
define i32* @test2() {
  ret i32* getelementptr ([0 x i32], [0 x i32]* @x, i32 0, i32 0)
}

; CHECK-LABEL: test3:
; CHECK-NEXT: .result i32{{$}}
; CHECK-NEXT: i32.const $push0=, y{{$}}
; CHECK=NEXT: return $pop0{{$}}
define i32* @test3() {
  ret i32* getelementptr ([50 x i32], [50 x i32]* @y, i32 0, i32 0)
}<commit_msg>[WebAssembly] Add tests for negative offsets with global variable addresses.<commit_after>; RUN: llc < %s -asm-verbose=false | FileCheck %s

; Test that constant offsets can be folded into global addresses.

target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
target triple = "wasm32-unknown-unknown"

@x = external global [0 x i32]
@y = global [50 x i32] zeroinitializer

; Test basic constant offsets of both defined and external symbols.

; CHECK-LABEL: test0:
; CHECK-NEXT: .result i32{{$}}
; CHECK-NEXT: i32.const $push0=, x+188{{$}}
; CHECK=NEXT: return $pop0{{$}}
define i32* @test0() {
  ret i32* getelementptr ([0 x i32], [0 x i32]* @x, i32 0, i32 47)
}

; CHECK-LABEL: test1:
; CHECK-NEXT: .result i32{{$}}
; CHECK-NEXT: i32.const $push0=, y+188{{$}}
; CHECK=NEXT: return $pop0{{$}}
define i32* @test1() {
  ret i32* getelementptr ([50 x i32], [50 x i32]* @y, i32 0, i32 47)
}

; Test zero offsets.

; CHECK-LABEL: test2:
; CHECK-NEXT: .result i32{{$}}
; CHECK-NEXT: i32.const $push0=, x{{$}}
; CHECK=NEXT: return $pop0{{$}}
define i32* @test2() {
  ret i32* getelementptr ([0 x i32], [0 x i32]* @x, i32 0, i32 0)
}

; CHECK-LABEL: test3:
; CHECK-NEXT: .result i32{{$}}
; CHECK-NEXT: i32.const $push0=, y{{$}}
; CHECK=NEXT: return $pop0{{$}}
define i32* @test3() {
  ret i32* getelementptr ([50 x i32], [50 x i32]* @y, i32 0, i32 0)
}

; Test negative offsets.

; CHECK-LABEL: test4:
; CHECK-NEXT: .result i32{{$}}
; CHECK-NEXT: i32.const $push0=, x-188{{$}}
; CHECK=NEXT: return $pop0{{$}}
define i32* @test4() {
  ret i32* getelementptr ([0 x i32], [0 x i32]* @x, i32 0, i32 -47)
}

; CHECK-LABEL: test5:
; CHECK-NEXT: .result i32{{$}}
; CHECK-NEXT: i32.const $push0=, y-188{{$}}
; CHECK=NEXT: return $pop0{{$}}
define i32* @test5() {
  ret i32* getelementptr ([50 x i32], [50 x i32]* @y, i32 0, i32 -47)
}
{'fraction_non_alphanumeric': 0.2, 'fraction_numerical': 0.1037037037037037, 'mean_word_length': 4.202680067001675, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4321628', 'n_tokens_mistral': 1462, 'n_tokens_neox': 1269, 'n_words': 398}