From: Heejin Ahn Date: Thu, 10 Jan 2019 23:12:07 +0000 (+0000) Subject: [WebAssembly] Fix stack pointer store check in RegStackify X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d5697a92c2eb244f7cba4102228f146fd8e9c1dc;p=llvm [WebAssembly] Fix stack pointer store check in RegStackify Summary: We now use __stack_pointer global and global.get/global.set instruction. This fixes the checking routine for stack_pointer writes accordingly. This also fixes the existing __stack_pointer test in reg-stackify.ll: That test used to pass not because of __stack_pointer clashes but because the function `stackpointer_callee` was not marked as `readnone`, so it was assumed to possibly write to memory arbitraily, and `global.set` instruction was marked as `mayStore` in the .td definition, so they were identified as intervening writes. After we added `readnone` to its attribute, this test fails without this patch. Reviewers: dschuff, sunfish Subscribers: jgravelle-google, sbc100, llvm-commits Differential Revision: https://reviews.llvm.org/D56094 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@350906 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Target/WebAssembly/WebAssemblyRegStackify.cpp b/lib/Target/WebAssembly/WebAssemblyRegStackify.cpp index ceb024b4be0..e991bf47e07 100644 --- a/lib/Target/WebAssembly/WebAssemblyRegStackify.cpp +++ b/lib/Target/WebAssembly/WebAssemblyRegStackify.cpp @@ -181,19 +181,6 @@ static void Query(const MachineInstr &MI, AliasAnalysis &AA, bool &Read, // Check for stores. if (MI.mayStore()) { Write = true; - - // Check for stores to __stack_pointer. - for (auto MMO : MI.memoperands()) { - const MachinePointerInfo &MPI = MMO->getPointerInfo(); - if (MPI.V.is()) { - auto PSV = MPI.V.get(); - if (const ExternalSymbolPseudoSourceValue *EPSV = - dyn_cast(PSV)) - if (StringRef(EPSV->getSymbol()) == "__stack_pointer") { - StackPointer = true; - } - } - } } else if (MI.hasOrderedMemoryRef()) { switch (MI.getOpcode()) { case WebAssembly::DIV_S_I32: @@ -258,6 +245,11 @@ static void Query(const MachineInstr &MI, AliasAnalysis &AA, bool &Read, } } + // Check for writes to __stack_pointer global. + if (MI.getOpcode() == WebAssembly::GLOBAL_SET_I32 && + strcmp(MI.getOperand(0).getSymbolName(), "__stack_pointer") == 0) + StackPointer = true; + // Analyze calls. if (MI.isCall()) { unsigned CalleeOpNo = WebAssembly::getCalleeOpNo(MI); diff --git a/test/CodeGen/WebAssembly/reg-stackify.ll b/test/CodeGen/WebAssembly/reg-stackify.ll index 2b36ba0e3ef..6b4487bc66f 100644 --- a/test/CodeGen/WebAssembly/reg-stackify.ll +++ b/test/CodeGen/WebAssembly/reg-stackify.ll @@ -634,7 +634,7 @@ bb10: ; preds = %bb9, %bb ; NOREGS-LABEL: stackpointer_dependency: ; NOREGS: call stackpointer_callee@FUNCTION ; NOREGS: global.set __stack_pointer -declare i32 @stackpointer_callee(i8* readnone, i8* readnone) +declare i32 @stackpointer_callee(i8* readnone, i8* readnone) nounwind readnone declare i8* @llvm.frameaddress(i32) define i32 @stackpointer_dependency(i8* readnone) { %2 = tail call i8* @llvm.frameaddress(i32 0)