[llvm] r300502 - [WebAssembly] Fix WebAssemblyOptimizeReturned after r300367

Jacob Gravelle via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 17 14:40:29 PDT 2017


Author: jgravelle
Date: Mon Apr 17 16:40:28 2017
New Revision: 300502

URL: http://llvm.org/viewvc/llvm-project?rev=300502&view=rev
Log:
[WebAssembly] Fix WebAssemblyOptimizeReturned after r300367

Summary:
Refactoring changed paramHasAttr(1 + i) to paramHasAttr(0), fix that to
paramHasAttr(i).
Add more tests to WebAssemblyOptimizeReturned that catch that
regression.

Reviewers: dschuff

Subscribers: jfb, sbc100, llvm-commits

Differential Revision: https://reviews.llvm.org/D32136

Modified:
    llvm/trunk/lib/Target/WebAssembly/WebAssemblyOptimizeReturned.cpp
    llvm/trunk/test/CodeGen/WebAssembly/returned.ll

Modified: llvm/trunk/lib/Target/WebAssembly/WebAssemblyOptimizeReturned.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/WebAssembly/WebAssemblyOptimizeReturned.cpp?rev=300502&r1=300501&r2=300502&view=diff
==============================================================================
--- llvm/trunk/lib/Target/WebAssembly/WebAssemblyOptimizeReturned.cpp (original)
+++ llvm/trunk/lib/Target/WebAssembly/WebAssemblyOptimizeReturned.cpp Mon Apr 17 16:40:28 2017
@@ -54,7 +54,7 @@ FunctionPass *llvm::createWebAssemblyOpt
 
 void OptimizeReturned::visitCallSite(CallSite CS) {
   for (unsigned i = 0, e = CS.getNumArgOperands(); i < e; ++i)
-    if (CS.paramHasAttr(0, Attribute::Returned)) {
+    if (CS.paramHasAttr(i, Attribute::Returned)) {
       Instruction *Inst = CS.getInstruction();
       Value *Arg = CS.getArgOperand(i);
       // Ignore constants, globals, undef, etc.

Modified: llvm/trunk/test/CodeGen/WebAssembly/returned.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/WebAssembly/returned.ll?rev=300502&r1=300501&r2=300502&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/WebAssembly/returned.ll (original)
+++ llvm/trunk/test/CodeGen/WebAssembly/returned.ll Mon Apr 17 16:40:28 2017
@@ -47,3 +47,34 @@ define void @test_constant_arg() {
   ret void
 }
 declare i32* @returns_arg(i32* returned)
+
+; Test that the optimization isn't performed on arguments without the
+; "returned" attribute.
+
+; CHECK-LABEL: test_other_skipped:
+; CHECK-NEXT: .param   i32, i32, f64{{$}}
+; CHECK-NEXT: {{^}} i32.call     $drop=, do_something at FUNCTION, $0, $1, $2{{$}}
+; CHECK-NEXT: {{^}} call     do_something_with_i32 at FUNCTION, $1{{$}}
+; CHECK-NEXT: {{^}} call     do_something_with_double at FUNCTION, $2{{$}}
+declare i32 @do_something(i32 returned, i32, double)
+declare void @do_something_with_i32(i32)
+declare void @do_something_with_double(double)
+define void @test_other_skipped(i32 %a, i32 %b, double %c) {
+    %call = call i32 @do_something(i32 %a, i32 %b, double %c)
+    call void @do_something_with_i32(i32 %b)
+    call void @do_something_with_double(double %c)
+    ret void
+}
+
+; Test that the optimization is performed on arguments other than the first.
+
+; CHECK-LABEL: test_second_arg:
+; CHECK-NEXT: .param   i32, i32{{$}}
+; CHECK-NEXT: .result  i32{{$}}
+; CHECK-NEXT: {{^}} i32.call     $push0=, do_something_else at FUNCTION, $0, $1{{$}}
+; CHECK-NEXT: return   $pop0{{$}}
+declare i32 @do_something_else(i32, i32 returned)
+define i32 @test_second_arg(i32 %a, i32 %b) {
+    %call = call i32 @do_something_else(i32 %a, i32 %b)
+    ret i32 %b
+}




More information about the llvm-commits mailing list