[WebAssembly] Don't perform the returned-argument optimization on constants.

llvm-svn: 254866
This commit is contained in:
Dan Gohman 2015-12-05 22:12:39 +00:00
parent a019e81df9
commit d85c3b1fbc
2 changed files with 17 additions and 0 deletions

View 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++;

View 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)