From: Dan Gohman Date: Sat, 5 Dec 2015 22:12:39 +0000 (+0000) Subject: [WebAssembly] Don't perform the returned-argument optimization on constants. X-Git-Url: http://plrg.eecs.uci.edu/git/?p=oota-llvm.git;a=commitdiff_plain;h=9eb92586b28e7d951f0ac320045885a320f2a0ab;hp=39f84fda2f1b44f926a313e138721d4b14d00da7;ds=sidebyside [WebAssembly] Don't perform the returned-argument optimization on constants. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@254866 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Target/WebAssembly/WebAssemblyOptimizeReturned.cpp b/lib/Target/WebAssembly/WebAssemblyOptimizeReturned.cpp index dea419c5975..4dc401a2c7c 100644 --- a/lib/Target/WebAssembly/WebAssemblyOptimizeReturned.cpp +++ b/lib/Target/WebAssembly/WebAssemblyOptimizeReturned.cpp @@ -57,6 +57,9 @@ void OptimizeReturned::visitCallSite(CallSite CS) { if (CS.paramHasAttr(1 + i, Attribute::Returned)) { Instruction *Inst = CS.getInstruction(); Value *Arg = CS.getArgOperand(i); + // Ignore constants, globals, undef, etc. + if (isa(Arg)) + continue; // Like replaceDominatedUsesWith but using Instruction/Use dominance. for (auto UI = Arg->use_begin(), UE = Arg->use_end(); UI != UE;) { Use &U = *UI++; diff --git a/test/CodeGen/WebAssembly/returned.ll b/test/CodeGen/WebAssembly/returned.ll index d65e2a8bc3e..9cfdc711a8a 100644 --- a/test/CodeGen/WebAssembly/returned.ll +++ b/test/CodeGen/WebAssembly/returned.ll @@ -33,3 +33,17 @@ entry: %call = tail call i8* @memcpy(i8* %p, i8* %s, i32 %n) ret i8* %p } + +; Test that the optimization isn't performed on constant arguments. + +; CHECK-LABEL: test_constant_arg: +; CHECK-NEXT: i32.const $push0=, global{{$}} +; CHECK-NEXT: call $discard=, returns_arg, $pop0{{$}} +; CHECK-NEXT: return{{$}} +@global = external global i32 +@addr = global i32* @global +define void @test_constant_arg() { + %call = call i32* @returns_arg(i32* @global) + ret void +} +declare i32* @returns_arg(i32* returned)