[llvm-branch-commits] [llvm] 2ec43a7 - [TargetMachine] Delete wasm special case from shouldAssumeDSOLocal

Fangrui Song via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Fri Dec 4 23:27:34 PST 2020


Author: Fangrui Song
Date: 2020-12-04T23:22:47-08:00
New Revision: 2ec43a7b2276673c5556e40c954b1874ee5ec072

URL: https://github.com/llvm/llvm-project/commit/2ec43a7b2276673c5556e40c954b1874ee5ec072
DIFF: https://github.com/llvm/llvm-project/commit/2ec43a7b2276673c5556e40c954b1874ee5ec072.diff

LOG: [TargetMachine] Delete wasm special case from shouldAssumeDSOLocal

Added: 
    llvm/test/CodeGen/WebAssembly/load-store-static.ll

Modified: 
    llvm/lib/Target/TargetMachine.cpp
    llvm/test/CodeGen/WebAssembly/load-store-pic.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/TargetMachine.cpp b/llvm/lib/Target/TargetMachine.cpp
index f648b27d695f..30f588193def 100644
--- a/llvm/lib/Target/TargetMachine.cpp
+++ b/llvm/lib/Target/TargetMachine.cpp
@@ -198,8 +198,8 @@ bool TargetMachine::shouldAssumeDSOLocal(const Module &M,
       // variables.
       if (!GV || F)
         return true;
-      // TODO Remove the special case for x86-32 and wasm.
-      if ((Arch == Triple::x86 || TT.isWasm()) && !GV->isThreadLocal())
+      // TODO Remove the special case for x86-32.
+      if (Arch == Triple::x86 && !GV->isThreadLocal())
         return true;
     }
   } else if (TT.isOSBinFormatELF()) {

diff  --git a/llvm/test/CodeGen/WebAssembly/load-store-pic.ll b/llvm/test/CodeGen/WebAssembly/load-store-pic.ll
index 9090c3520b57..5f09025b88e2 100644
--- a/llvm/test/CodeGen/WebAssembly/load-store-pic.ll
+++ b/llvm/test/CodeGen/WebAssembly/load-store-pic.ll
@@ -1,4 +1,3 @@
-; RUN: llc < %s -asm-verbose=false -wasm-disable-explicit-locals -wasm-keep-registers | FileCheck %s -check-prefixes=NON-PIC,CHECK
 ; RUN: llc < %s -asm-verbose=false -relocation-model=pic -fast-isel -wasm-disable-explicit-locals -wasm-keep-registers | FileCheck %s -check-prefixes=PIC,CHECK
 ; RUN: llc < %s -asm-verbose=false -relocation-model=pic -fast-isel=false -wasm-disable-explicit-locals -wasm-keep-registers | FileCheck %s -check-prefixes=PIC,CHECK
 
@@ -24,9 +23,6 @@ define i32 @load_hidden_global() {
 ; PIC-NEXT:    i32.const $push[[L1:[0-9]+]]=, hidden_global at MBREL{{$}}
 ; PIC-NEXT:    i32.add $push[[L2:[0-9]+]]=, $pop[[L0]], $pop[[L1]]{{$}}
 ; PIC-NEXT:    i32.load $push[[L3:[0-9]+]]=, 0($pop[[L2]]){{$}}
-
-; NON-PIC:         i32.const $push0=, 0{{$}}
-; NON-PIC-NEXT:    i32.load $push1=, hidden_global($pop0){{$}}
 ; CHECK-NEXT:    end_function
 
   %1 = load i32, i32* @hidden_global
@@ -41,9 +37,6 @@ define i32 @load_hidden_global_offset() {
 ; PIC-NEXT:    i32.const $push[[L3:[0-9]+]]=, 20{{$}}
 ; PIC-NEXT:    i32.add $push[[L4:[0-9]+]]=, $pop[[L2]], $pop[[L3]]{{$}}
 ; PIC-NEXT:    i32.load $push{{[0-9]+}}=, 0($pop[[L4]]){{$}}
-
-; NON-PIC:     i32.const $push0=, 0{{$}}
-; NON-PIC-NEXT:i32.load  $push1=, hidden_global_array+20($pop0){{$}}
 ; CHECK-NEXT:  end_function
 
   %1 = getelementptr [10 x i32], [10 x i32]* @hidden_global_array, i32 0, i32 5
@@ -59,9 +52,6 @@ define void @store_hidden_global(i32 %n) {
 ; PIC-NEXT:    i32.const $push[[L1:[0-9]+]]=, hidden_global at MBREL{{$}}
 ; PIC-NEXT:    i32.add $push[[L2:[0-9]+]]=, $pop[[L0]], $pop[[L1]]{{$}}
 ; PIC-NEXT:    i32.store 0($pop[[L2]]), $0{{$}}
-
-; NON-PIC:       i32.const $push0=, 0{{$}}
-; NON-PIC-NEXT:  i32.store hidden_global($pop0), $0{{$}}
 ; CHECK-NEXT:    end_function
 
   store i32 %n, i32* @hidden_global
@@ -77,8 +67,6 @@ define void @store_hidden_global_offset(i32 %n) {
 ; PIC-NEXT:    i32.add $push[[L4:[0-9]+]]=, $pop[[L2]], $pop[[L3]]{{$}}
 ; PIC-NEXT:    i32.store 0($pop[[L4]]), $0{{$}}
 
-; NON-PIC:      i32.const $push0=, 0{{$}}
-; NON-PIC-NEXT: i32.store hidden_global_array+20($pop0), $0{{$}}
 ; CHECK-NEXT:   end_function
 
   %1 = getelementptr [10 x i32], [10 x i32]* @hidden_global_array, i32 0, i32 5
@@ -95,8 +83,6 @@ define i32 @load_external_global() {
 ; PIC:          global.get $push[[L0:[0-9]+]]=, external_global at GOT{{$}}
 ; PIC-NEXT:     i32.load $push{{[0-9]+}}=, 0($pop[[L0]]){{$}}
 
-; NON-PIC:      i32.const $push0=, 0{{$}}
-; NON-PIC-NEXT: i32.load $push1=, external_global($pop0){{$}}
 ; CHECK-NEXT:   end_function
 
   %1 = load i32, i32* @external_global
@@ -110,8 +96,6 @@ define i32 @load_external_global_offset() {
 ; PIC-NEXT:     i32.add $push[[L2:[0-9]+]]=, $pop[[L0]], $pop[[L1]]{{$}}
 ; PIC-NEXT:     i32.load $push{{[0-9]+}}=, 0($pop[[L2]]){{$}}
 
-; NON-PIC:      i32.const $push0=, 0{{$}}
-; NON-PIC-NEXT: i32.load $push1=, external_global_array+20($pop0){{$}}
 ; CHECK-NEXT:   end_function
 
   %1 = getelementptr [10 x i32], [10 x i32]* @external_global_array, i32 0, i32 5
@@ -126,8 +110,6 @@ define void @store_external_global(i32 %n) {
 ; PIC:          global.get $push[[L0:[0-9]+]]=, external_global at GOT{{$}}
 ; PIC-NEXT:     i32.store 0($pop[[L0]]), $0{{$}}
 
-; NON-PIC:      i32.const $push0=, 0{{$}}
-; NON-PIC-NEXT: i32.store external_global($pop0), $0{{$}}
 ; CHECK-NEXT:   end_function
 
   store i32 %n, i32* @external_global
@@ -141,8 +123,6 @@ define void @store_external_global_offset(i32 %n) {
 ; PIC-NEXT:     i32.add $push[[L2:[0-9]+]]=, $pop[[L0]], $pop[[L1]]{{$}}
 ; PIC-NEXT:     i32.store 0($pop[[L2]]), $0{{$}}
 
-; NON-PIC:      i32.const $push0=, 0{{$}}
-; NON-PIC-NEXT: i32.store external_global_array+20($pop0), $0{{$}}
 ; CHECK-NEXT:   end_function
 
   %1 = getelementptr [10 x i32], [10 x i32]* @external_global_array, i32 0, i32 5

diff  --git a/llvm/test/CodeGen/WebAssembly/load-store-static.ll b/llvm/test/CodeGen/WebAssembly/load-store-static.ll
new file mode 100644
index 000000000000..3ad764a0db61
--- /dev/null
+++ b/llvm/test/CodeGen/WebAssembly/load-store-static.ll
@@ -0,0 +1,106 @@
+; RUN: llc < %s -asm-verbose=false -wasm-disable-explicit-locals -wasm-keep-registers | FileCheck %s -check-prefixes=NON-PIC,CHECK
+
+target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
+target triple = "wasm32-unknown-emscripten"
+
+ at hidden_global         = external hidden global i32
+ at hidden_global_array   = external hidden global [10 x i32]
+ at external_global       = external dso_local global i32
+ at external_global_array = external dso_local global [10 x i32]
+
+declare i32 @foo();
+
+; For hidden symbols PIC code needs to offset all loads and stores
+; by the value of the __memory_base global
+
+define i32 @load_hidden_global() {
+; CHECK-LABEL: load_hidden_global:
+; NON-PIC:         i32.const $push0=, 0{{$}}
+; NON-PIC-NEXT:    i32.load $push1=, hidden_global($pop0){{$}}
+; CHECK-NEXT:    end_function
+
+  %1 = load i32, i32* @hidden_global
+  ret i32 %1
+}
+
+define i32 @load_hidden_global_offset() {
+; CHECK-LABEL: load_hidden_global_offset:
+; NON-PIC:     i32.const $push0=, 0{{$}}
+; NON-PIC-NEXT:i32.load  $push1=, hidden_global_array+20($pop0){{$}}
+; CHECK-NEXT:  end_function
+
+  %1 = getelementptr [10 x i32], [10 x i32]* @hidden_global_array, i32 0, i32 5
+  %2 = load i32, i32* %1
+  ret i32 %2
+}
+
+; Store to a hidden global
+
+define void @store_hidden_global(i32 %n) {
+; CHECK-LABEL: store_hidden_global:
+; NON-PIC:       i32.const $push0=, 0{{$}}
+; NON-PIC-NEXT:  i32.store hidden_global($pop0), $0{{$}}
+; CHECK-NEXT:    end_function
+
+  store i32 %n, i32* @hidden_global
+  ret void
+}
+
+define void @store_hidden_global_offset(i32 %n) {
+; CHECK-LABEL: store_hidden_global_offset:
+; NON-PIC:      i32.const $push0=, 0{{$}}
+; NON-PIC-NEXT: i32.store hidden_global_array+20($pop0), $0{{$}}
+; CHECK-NEXT:   end_function
+
+  %1 = getelementptr [10 x i32], [10 x i32]* @hidden_global_array, i32 0, i32 5
+  store i32 %n, i32* %1
+  ret void
+}
+
+; For non-hidden globals PIC code has to load the address from a wasm global
+; using the @GOT relocation type.
+
+
+define i32 @load_external_global() {
+; CHECK-LABEL:  load_external_global:
+; NON-PIC:      i32.const $push0=, 0{{$}}
+; NON-PIC-NEXT: i32.load $push1=, external_global($pop0){{$}}
+; CHECK-NEXT:   end_function
+
+  %1 = load i32, i32* @external_global
+  ret i32 %1
+}
+
+define i32 @load_external_global_offset() {
+; CHECK-LABEL:  load_external_global_offset:
+; NON-PIC:      i32.const $push[[L0:[0-9]+]]=, 0{{$}}
+; NON-PIC-NEXT: i32.load $push{{[0-9]+}}=, external_global_array+20($pop[[L0]]){{$}}
+; CHECK-NEXT:   end_function
+
+  %1 = getelementptr [10 x i32], [10 x i32]* @external_global_array, i32 0, i32 5
+  %2 = load i32, i32* %1
+  ret i32 %2
+}
+
+; Store to a non-hidden global via the wasm global.
+
+define void @store_external_global(i32 %n) {
+; CHECK-LABEL:  store_external_global:
+; NON-PIC:      i32.const $push0=, 0{{$}}
+; NON-PIC-NEXT: i32.store external_global($pop0), $0{{$}}
+; CHECK-NEXT:   end_function
+
+  store i32 %n, i32* @external_global
+  ret void
+}
+
+define void @store_external_global_offset(i32 %n) {
+; CHECK-LABEL:  store_external_global_offset:
+; NON-PIC:      i32.const $push0=, 0{{$}}
+; NON-PIC-NEXT: i32.store external_global_array+20($pop0), $0{{$}}
+; CHECK-NEXT:   end_function
+
+  %1 = getelementptr [10 x i32], [10 x i32]* @external_global_array, i32 0, i32 5
+  store i32 %n, i32* %1
+  ret void
+}


        


More information about the llvm-branch-commits mailing list