diff --git a/llvm/benchmarks/SandboxIRBench.cpp b/llvm/benchmarks/SandboxIRBench.cpp index c646ba6290daff..6cff2eefdb19f2 100644 --- a/llvm/benchmarks/SandboxIRBench.cpp +++ b/llvm/benchmarks/SandboxIRBench.cpp @@ -134,6 +134,45 @@ template static void RAUW(benchmark::State &State) { } } +static std::string generateRUOWIR(unsigned NumOperands) { + std::stringstream SS; + auto GenOps = [&SS, NumOperands]() { + for (auto Cnt : seq(0, NumOperands)) { + SS << "i8 %arg" << Cnt; + bool IsLast = Cnt + 1 == NumOperands; + if (!IsLast) + SS << ", "; + } + }; + + SS << "define void @foo("; + GenOps(); + SS << ") {\n"; + + SS << " call void @foo("; + GenOps(); + SS << ")\n"; + SS << "ret void"; + SS << "}"; + return SS.str(); +} + +template static void RUOW(benchmark::State &State) { + LLVMContext LLVMCtx; + sandboxir::Context Ctx(LLVMCtx); + std::unique_ptr LLVMM; + unsigned NumOperands = State.range(0); + auto *BB = genIR(LLVMM, LLVMCtx, Ctx, generateRUOWIR, NumOperands); + + auto It = BB->begin(); + auto *F = BB->getParent(); + auto *Arg0 = F->getArg(0); + auto *Arg1 = F->getArg(1); + auto *Call = &*It++; + for (auto _ : State) + Call->replaceUsesOfWith(Arg0, Arg1); +} + BENCHMARK(GetType); BENCHMARK(GetType); @@ -143,4 +182,7 @@ BENCHMARK(BBWalk)->Args({1024}); BENCHMARK(RAUW)->Args({512}); BENCHMARK(RAUW)->Args({512}); +BENCHMARK(RUOW)->Args({4096}); +BENCHMARK(RUOW)->Args({4096}); + BENCHMARK_MAIN();