[WebAssembly] Don't perform the returned-argument optimization on constants.
authorDan Gohman <dan433584@gmail.com>
Sat, 5 Dec 2015 22:12:39 +0000 (22:12 +0000)
committerDan Gohman <dan433584@gmail.com>
Sat, 5 Dec 2015 22:12:39 +0000 (22:12 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@254866 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/WebAssembly/WebAssemblyOptimizeReturned.cpp
test/CodeGen/WebAssembly/returned.ll

index dea419c5975c37bb190deedcc7436ed80229c9c0..4dc401a2c7cc776ddd99b1430dcde21abad8fdc1 100644 (file)
@@ -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<Constant>(Arg))
+        continue;
       // Like replaceDominatedUsesWith but using Instruction/Use dominance.
       for (auto UI = Arg->use_begin(), UE = Arg->use_end(); UI != UE;) {
         Use &U = *UI++;
index d65e2a8bc3e5a755d210dbe1aedfc55ab4348588..9cfdc711a8a3b7792db878fb25706f639e9153b5 100644 (file)
@@ -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)