aboutsummaryrefslogtreecommitdiffstats
path: root/benchmark-flags
blob: 1168ec0f0969947662d899cd949d53c1a8324a08 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/bin/sh
# See LICENSE file for copyright and license details.

set -e

export LD_LIBRARY_PATH=bin
if test "${TRIES}" = ""; then
	TRIES=10
fi

# List all flags that affect the object files
list_test_flags() {
	cat <<EOF
-fdata-sections -fcrossjumping -fexpensive-optimizations -ffunction-sections
-fkeep-inline-functions -fomit-frame-pointer -freorder-blocks-and-partition
-ftree-ter -falign-functions=0 -fmerge-all-constants -fmerge-constants
EOF
}

cppflags="-DIGNORE_BEHEXING"
base_flags='-march=native -O0'
test_flags=" $(echo $(list_test_flags)) "

pass=1
exec 4>.benchmark.so.far

while true; do
	exec 3>.benchmarks

	for _try in $(seq ${TRIES}); do
		for test_flag in "" ${test_flags}; do
			flags="${test_flag} ${base_flags}"
			make -B all COPTIMISE="${flags}" CPPFLAGS="${cppflags} $*"
			make check
			if test "${test_flag}" = ""; then
				test_flag=zzz
			fi
			echo "$(bin/benchmark || echo error) ${test_flag}" >&3
		done
	done

	exec 3<&-

	! grep ^error .benchmarks >/dev/null 2>/dev/null

	good_flag="$(median < .benchmarks | sort -n | cut -d ' ' -f 2 | sed 1q)"
	if test "${good_flag}" = zzz || test $pass = 2; then
		if test $pass = 1; then
			pass=2
			base_flags="$(echo "${base_flags}" | sed -e 's/ -O0//')"
			test_flags="-O0 -O1 -O2 -O3 -Ofast -Os"
		else
			if ! test "${good_flag}" = zzz; then
				base_flags="${base_flags} ${good_flag}"
				echo "${good_flag}" >&4
			fi
			echo
			echo
			echo "Good flags:"
			echo "${base_flags}"
			exec 4<&-
			exit 0
		fi
	else
		echo "${good_flag}" >&4
		base_flags="${base_flags} ${good_flag}"
		test_flags="$(echo "${test_flags}" | sed -e "s/ ${good_flag} / /")"
	fi
done

#    None of these GCC flags affect the object files.
# -faggressive-loop-optimizations -fauto-inc-dec -fbranch-target-load-optimize
# -fbranch-target-load-optimize2 -fbtr-bb-exclusive -fcaller-saves -fcheck-data-deps
# -fcombine-stack-adjustments -fconserve-stack -fcompare-elim -fcprop-registers
# -fcse-follow-jumps -fcse-skip-blocks -fcx-fortran-rules -fcx-limited-range -fdce
# -fdelete-null-pointer-checks -fdevirtualize -fdevirtualize-speculatively -fdse
# -fearly-inlining -fipa-sra  -ffat-lto-objects -fbranch-probabilities
# -fassociative-math -fforward-propagate -ffunction-sections -fforward-propagate
# -ffast-math -ffinite-math-only -ffloat-store -fgcse -fgcse-after-reload -fgcse-las
# -fgcse-lm -fgraphite-identity -fgcse-sm -fhoist-adjacent-loads -fif-conversion
# -fif-conversion2 -findirect-inlining -finline-functions -finline-functions-called-once
# -finline-small-functions -fipa-cp -fipa-cp-clone -fipa-pta -fipa-profile
# -fipa-pure-const -fipa-reference -fira-hoist-pressure -fira-loop-pressure
# -fno-ira-share-save-slots -fno-ira-share-spill-slots -fisolate-erroneous-paths-dereference
# -fisolate-erroneous-paths-attribute -fivopts -fkeep-static-consts -flive-range-shrinkage
# -floop-block -floop-interchange -floop-strip-mine -floop-nest-optimize
# -floop-parallelize-all -fmodulo-sched -fmodulo-sched-allow-regmoves -fmove-loop-invariants
# -fno-branch-count-reg -fno-defer-pop -fno-function-cse -fno-guess-branch-probability
# -fno-defer-pop -fno-function-cse -fno-guess-branch-probability -fno-inline -fno-math-errno
# -fno-peephole -fno-peephole2 -fno-sched-interblock -fno-sched-spec -fno-signed-zeros
# -fno-toplevel-reorder -fno-trapping-math -fno-zero-initialized-in-bss
# -foptimize-sibling-calls -fpartial-inlining -fpeel-loops -fpredictive-commoning
# -fprefetch-loop-arrays -fprofile-report -fprofile-use -fprofile-values
# -fprofile-reorder-functions -freciprocal-math -free -frename-registers -freorder-blocks
# -frerun-cse-after-loop -freschedule-modulo-scheduled-loops -frounding-math
# -fsched2-use-superblocks -fsched-pressure -fsched-spec-load -fsched-spec-load-dangerous
# -fsched-group-heuristic -fsched-critical-path-heuristic -fsched-spec-insn-heuristic
# -fsched-rank-heuristic -fsched-last-insn-heuristic -fsched-dep-count-heuristic
# -fselective-scheduling -fselective-scheduling2 -fsel-sched-pipelining
# -fsel-sched-pipelining-outer-loops -fshrink-wrap -fsignaling-nans
# -fsingle-precision-constant -fstrict-overflow -fthread-jumps -ftracer -ftree-bit-ccp
# -ftree-builtin-call-dce -ftree-ccp -ftree-ch -ftree-copyrename -ftree-dce
# -ftree-dominator-opts -ftree-dse -ftree-forwprop -ftree-fre -ftree-loop-if-convert
# -ftree-loop-if-convert-stores -ftree-loop-im -ftree-phiprop -ftree-loop-distribution
# -ftree-loop-distribute-patterns -ftree-loop-ivcanon -ftree-loop-linear
# -ftree-loop-optimize -ftree-loop-vectorize -ftree-pre -ftree-partial-pre -ftree-pta
# -ftree-reassoc -ftree-sink -ftree-slsr -ftree-sra -ftree-vectorize -ftree-vrp
# -funit-at-a-time -funroll-all-loops -funroll-loops -funsafe-loop-optimizations
# -funsafe-math-optimizations -funswitch-loops -fvariable-expansion-in-unroller
# -fvect-cost-model -fvpt -fweb -fprofile-correction -freorder-functions
# -fschedule-insns -fschedule-insns2 -fsplit-ivs-in-unroller -fsplit-wide-types
# -fstrict-aliasing -ftree-coalesce-vars -ftree-copy-prop -ftree-switch-conversion
# -ftree-switch-conversion -ftree-tail-merge -ftree-coalesce-inlined-vars
# -falign-jumps=0 -falign-labels=0 -falign-loops=0 -ftree-parallelize-loops=10
# -fsched-stalled-insns-dep=0 -fsched-stalled-insns=0