Index: llvm/lib/CodeGen/CodeGenPrepare.cpp =================================================================== --- llvm/lib/CodeGen/CodeGenPrepare.cpp +++ llvm/lib/CodeGen/CodeGenPrepare.cpp @@ -2279,7 +2279,8 @@ if (!Arg->getType()->isPointerTy()) continue; unsigned AS = Arg->getType()->getPointerAddressSpace(); - return optimizeMemoryInst(CI, Arg, Arg->getType(), AS); + if (optimizeMemoryInst(CI, Arg, Arg->getType(), AS)) + return true; } IntrinsicInst *II = dyn_cast(CI); Index: llvm/test/CodeGen/Generic/addr-sink-call-multi-arg.ll =================================================================== --- /dev/null +++ llvm/test/CodeGen/Generic/addr-sink-call-multi-arg.ll @@ -0,0 +1,20 @@ +; RUN: llc --stop-after=codegenprepare < %s | FileCheck %s + +declare void @f(ptr, ptr) cold + +define void @g(i1 %c1, ptr %p, i32 %i) { +entry: + %a0 = getelementptr i32 *, ptr %p, i32 %i + %a1 = getelementptr i32 *, ptr %p, i32 4 + br i1 %c1, label %if.then, label %exit + +if.then: +; Check that we don't give up on the first argument. +; CHECK: %sunkaddr = getelementptr i8, ptr %p, i64 32 +; CHECK: call void @f(ptr %a0, ptr %sunkaddr) + call void @f(ptr %a0, ptr %a1) + br label %exit + +exit: + ret void +}