Skip to content

Commit 0060b1b

Browse files
SC llvm teamSC llvm team
authored andcommitted
Merged main:fd784726db70 into amd-gfx:1c4d2a5930bb
Local branch amd-gfx 1c4d2a5 Merged main:e072cffe3b63 into amd-gfx:c0b9c269979b Remote branch main fd78472 [libc++] Rewrite minmax_element benchmark
2 parents 1c4d2a5 + fd78472 commit 0060b1b

File tree

4 files changed

+67
-25
lines changed

4 files changed

+67
-25
lines changed

libcxx/test/benchmarks/algorithms/min_max_element.bench.cpp

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,33 +6,42 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
// UNSUPPORTED: c++03, c++11, c++14
9+
// UNSUPPORTED: c++03, c++11, c++14, c++17
1010

1111
#include <algorithm>
12+
#include <vector>
1213

13-
#include "common.h"
14+
#include <benchmark/benchmark.h>
1415

15-
namespace {
16-
template <class ValueType, class Order>
17-
struct MinMaxElement {
18-
size_t Quantity;
16+
void run_sizes(auto benchmark) {
17+
benchmark->Arg(1)
18+
->Arg(2)
19+
->Arg(3)
20+
->Arg(4)
21+
->Arg(64)
22+
->Arg(512)
23+
->Arg(1024)
24+
->Arg(4000)
25+
->Arg(4096)
26+
->Arg(5500)
27+
->Arg(64000)
28+
->Arg(65536)
29+
->Arg(70000);
30+
}
1931

20-
void run(benchmark::State& state) const {
21-
runOpOnCopies<ValueType>(state, Quantity, Order(), BatchSize::CountElements, [](auto& Copy) {
22-
benchmark::DoNotOptimize(std::minmax_element(Copy.begin(), Copy.end()));
23-
});
24-
}
32+
template <class T>
33+
void BM_std_minmax_element(benchmark::State& state) {
34+
std::vector<T> vec(state.range(), 3);
2535

26-
std::string name() const {
27-
return "BM_MinMaxElement" + ValueType::name() + Order::name() + "_" + std::to_string(Quantity);
36+
for (auto _ : state) {
37+
benchmark::DoNotOptimize(vec);
38+
benchmark::DoNotOptimize(std::minmax_element(vec.begin(), vec.end()));
2839
}
29-
};
30-
} // namespace
31-
32-
int main(int argc, char** argv) {
33-
benchmark::Initialize(&argc, argv);
34-
if (benchmark::ReportUnrecognizedArguments(argc, argv))
35-
return 1;
36-
makeCartesianProductBenchmark<MinMaxElement, AllValueTypes, AllOrders>(Quantities);
37-
benchmark::RunSpecifiedBenchmarks();
3840
}
41+
42+
BENCHMARK(BM_std_minmax_element<char>)->Apply(run_sizes);
43+
BENCHMARK(BM_std_minmax_element<short>)->Apply(run_sizes);
44+
BENCHMARK(BM_std_minmax_element<int>)->Apply(run_sizes);
45+
BENCHMARK(BM_std_minmax_element<long long>)->Apply(run_sizes);
46+
47+
BENCHMARK_MAIN();

llvm/include/llvm/Config/llvm-config.h.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
/* Indicate that this is LLVM compiled from the amd-gfx branch. */
1818
#define LLVM_HAVE_BRANCH_AMD_GFX
19-
#define LLVM_MAIN_REVISION 522213
19+
#define LLVM_MAIN_REVISION 522215
2020

2121
/* Define if LLVM_ENABLE_DUMP is enabled */
2222
#cmakedefine LLVM_ENABLE_DUMP

llvm/lib/Transforms/Scalar/StraightLineStrengthReduce.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
#include "llvm/InitializePasses.h"
7979
#include "llvm/Pass.h"
8080
#include "llvm/Support/Casting.h"
81+
#include "llvm/Support/DebugCounter.h"
8182
#include "llvm/Support/ErrorHandling.h"
8283
#include "llvm/Transforms/Scalar.h"
8384
#include "llvm/Transforms/Utils/Local.h"
@@ -93,6 +94,9 @@ using namespace PatternMatch;
9394
static const unsigned UnknownAddressSpace =
9495
std::numeric_limits<unsigned>::max();
9596

97+
DEBUG_COUNTER(StraightLineStrengthReduceCounter, "slsr-counter",
98+
"Controls whether rewriteCandidateWithBasis is executed.");
99+
96100
namespace {
97101

98102
class StraightLineStrengthReduceLegacyPass : public FunctionPass {
@@ -268,8 +272,8 @@ FunctionPass *llvm::createStraightLineStrengthReducePass() {
268272
bool StraightLineStrengthReduce::isBasisFor(const Candidate &Basis,
269273
const Candidate &C) {
270274
return (Basis.Ins != C.Ins && // skip the same instruction
271-
// They must have the same type too. Basis.Base == C.Base doesn't
272-
// guarantee their types are the same (PR23975).
275+
// They must have the same type too. Basis.Base == C.Base
276+
// doesn't guarantee their types are the same (PR23975).
273277
Basis.Ins->getType() == C.Ins->getType() &&
274278
// Basis must dominate C in order to rewrite C with respect to Basis.
275279
DT->dominates(Basis.Ins->getParent(), C.Ins->getParent()) &&
@@ -610,6 +614,9 @@ Value *StraightLineStrengthReduce::emitBump(const Candidate &Basis,
610614

611615
void StraightLineStrengthReduce::rewriteCandidateWithBasis(
612616
const Candidate &C, const Candidate &Basis) {
617+
if (!DebugCounter::shouldExecute(StraightLineStrengthReduceCounter))
618+
return;
619+
613620
assert(C.CandidateKind == Basis.CandidateKind && C.Base == Basis.Base &&
614621
C.Stride == Basis.Stride);
615622
// We run rewriteCandidateWithBasis on all candidates in a post-order, so the

llvm/test/Other/debugcounter-slsr.ll

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
; REQUIRES: asserts
2+
; RUN: opt -passes=slsr -S -debug-counter=slsr-counter=1 < %s | FileCheck %s
3+
4+
; Test that, with debug counters on, we will skip the first slsr opportunity.
5+
6+
define void @stride_is_2s(i32 %b, i32 %s) {
7+
; CHECK-LABEL: @stride_is_2s(
8+
; CHECK-NEXT: %s2 = shl i32 %s, 1
9+
; CHECK-NEXT: %t1 = add i32 %b, %s2
10+
; CHECK-NEXT: call void @foo(i32 %t1)
11+
; CHECK-NEXT: %s4 = shl i32 %s, 2
12+
; CHECK-NEXT: %t2 = add i32 %b, %s4
13+
; CHECK-NEXT: call void @foo(i32 %t2)
14+
; CHECK-NEXT: ret void
15+
;
16+
%s2 = shl i32 %s, 1
17+
%t1 = add i32 %b, %s2
18+
call void @foo(i32 %t1)
19+
%s4 = shl i32 %s, 2
20+
%t2 = add i32 %b, %s4
21+
call void @foo(i32 %t2)
22+
ret void
23+
}
24+
25+
declare void @foo(i32)
26+

0 commit comments

Comments
 (0)