diff options
author | Ian Romanick <[email protected]> | 2019-11-16 13:19:47 -0800 |
---|---|---|
committer | Ian Romanick <[email protected]> | 2019-11-22 08:16:06 -0800 |
commit | ca353285cb07c36bec0b7aa2f96df6d4c6827ff0 (patch) | |
tree | 82950fb66ac285c3e81028b823a2899565bf6685 /src/compiler | |
parent | ccefce46cb8e9030b3a9134964ab2f660f66391c (diff) |
nir/range_analysis: Make sure the table validation only occurs once
All of the tables are static const, so they only need to be validated
once. As noted in the previous commit, the compiler should be able to
eliminate all of this code when the assertions would pass. Even with
the help of the previous commit, this does not always occur.
-Og: -95.688 +/- 3.91935 (-24.9562% +/- 1.0222%) N=5
-O1: No difference proven at 95.0% confidence. N=5
-O2: -1.962 +/- 0.85001 (-0.860013% +/- 0.372589%) N=5
Reviewed-by: Eric Anholt <[email protected]>
Diffstat (limited to 'src/compiler')
-rw-r--r-- | src/compiler/nir/nir_range_analysis.c | 96 |
1 files changed, 58 insertions, 38 deletions
diff --git a/src/compiler/nir/nir_range_analysis.c b/src/compiler/nir/nir_range_analysis.c index 0eaa97aafc2..df5d4dab9af 100644 --- a/src/compiler/nir/nir_range_analysis.c +++ b/src/compiler/nir/nir_range_analysis.c @@ -221,19 +221,27 @@ analyze_constant(const struct nir_alu_instr *instr, unsigned src, #ifndef NDEBUG #define ASSERT_TABLE_IS_COMMUTATIVE(t) \ do { \ - _Pragma("GCC unroll 7") \ - for (unsigned r = 0; r < ARRAY_SIZE(t); r++) { \ + static bool first = true; \ + if (first) { \ + first = false; \ _Pragma("GCC unroll 7") \ - for (unsigned c = 0; c < ARRAY_SIZE(t[0]); c++) \ - assert(t[r][c] == t[c][r]); \ + for (unsigned r = 0; r < ARRAY_SIZE(t); r++) { \ + _Pragma("GCC unroll 7") \ + for (unsigned c = 0; c < ARRAY_SIZE(t[0]); c++) \ + assert(t[r][c] == t[c][r]); \ + } \ } \ } while (false) #define ASSERT_TABLE_IS_DIAGONAL(t) \ do { \ - _Pragma("GCC unroll 7") \ - for (unsigned r = 0; r < ARRAY_SIZE(t); r++) \ - assert(t[r][r] == r); \ + static bool first = true; \ + if (first) { \ + first = false; \ + _Pragma("GCC unroll 7") \ + for (unsigned r = 0; r < ARRAY_SIZE(t); r++) \ + assert(t[r][r] == r); \ + } \ } while (false) static enum ssa_ranges @@ -261,19 +269,23 @@ union_ranges(enum ssa_ranges a, enum ssa_ranges b) */ #define ASSERT_UNION_OF_OTHERS_MATCHES_UNKNOWN_2_SOURCE(t) \ do { \ - _Pragma("GCC unroll 7") \ - for (unsigned i = 0; i < last_range; i++) { \ - enum ssa_ranges col_range = t[i][unknown + 1]; \ - enum ssa_ranges row_range = t[unknown + 1][i]; \ + static bool first = true; \ + if (first) { \ + first = false; \ + _Pragma("GCC unroll 7") \ + for (unsigned i = 0; i < last_range; i++) { \ + enum ssa_ranges col_range = t[i][unknown + 1]; \ + enum ssa_ranges row_range = t[unknown + 1][i]; \ \ - _Pragma("GCC unroll 5") \ - for (unsigned j = unknown + 2; j < last_range; j++) { \ - col_range = union_ranges(col_range, t[i][j]); \ - row_range = union_ranges(row_range, t[j][i]); \ - } \ + _Pragma("GCC unroll 5") \ + for (unsigned j = unknown + 2; j < last_range; j++) { \ + col_range = union_ranges(col_range, t[i][j]); \ + row_range = union_ranges(row_range, t[j][i]); \ + } \ \ - assert(col_range == t[i][unknown]); \ - assert(row_range == t[unknown][i]); \ + assert(col_range == t[i][unknown]); \ + assert(row_range == t[unknown][i]); \ + } \ } \ } while (false) @@ -291,12 +303,16 @@ union_ranges(enum ssa_ranges a, enum ssa_ranges b) #define ASSERT_UNION_OF_EQ_AND_STRICT_INEQ_MATCHES_NONSTRICT_2_SOURCE(t) \ do { \ - _Pragma("GCC unroll 7") \ - for (unsigned i = 0; i < last_range; i++) { \ - assert(union_ranges(t[i][lt_zero], t[i][eq_zero]) == t[i][le_zero]); \ - assert(union_ranges(t[i][gt_zero], t[i][eq_zero]) == t[i][ge_zero]); \ - assert(union_ranges(t[lt_zero][i], t[eq_zero][i]) == t[le_zero][i]); \ - assert(union_ranges(t[gt_zero][i], t[eq_zero][i]) == t[ge_zero][i]); \ + static bool first = true; \ + if (first) { \ + first = false; \ + _Pragma("GCC unroll 7") \ + for (unsigned i = 0; i < last_range; i++) { \ + assert(union_ranges(t[i][lt_zero], t[i][eq_zero]) == t[i][le_zero]); \ + assert(union_ranges(t[i][gt_zero], t[i][eq_zero]) == t[i][ge_zero]); \ + assert(union_ranges(t[lt_zero][i], t[eq_zero][i]) == t[le_zero][i]); \ + assert(union_ranges(t[gt_zero][i], t[eq_zero][i]) == t[ge_zero][i]); \ + } \ } \ } while (false) @@ -322,21 +338,25 @@ union_ranges(enum ssa_ranges a, enum ssa_ranges b) #define ASSERT_UNION_OF_DISJOINT_MATCHES_UNKNOWN_2_SOURCE(t) \ do { \ - _Pragma("GCC unroll 7") \ - for (unsigned i = 0; i < last_range; i++) { \ - assert(union_ranges(t[i][lt_zero], t[i][ge_zero]) == \ - t[i][unknown]); \ - assert(union_ranges(t[i][le_zero], t[i][gt_zero]) == \ - t[i][unknown]); \ - assert(union_ranges(t[i][eq_zero], t[i][ne_zero]) == \ - t[i][unknown]); \ + static bool first = true; \ + if (first) { \ + first = false; \ + _Pragma("GCC unroll 7") \ + for (unsigned i = 0; i < last_range; i++) { \ + assert(union_ranges(t[i][lt_zero], t[i][ge_zero]) == \ + t[i][unknown]); \ + assert(union_ranges(t[i][le_zero], t[i][gt_zero]) == \ + t[i][unknown]); \ + assert(union_ranges(t[i][eq_zero], t[i][ne_zero]) == \ + t[i][unknown]); \ \ - assert(union_ranges(t[lt_zero][i], t[ge_zero][i]) == \ - t[unknown][i]); \ - assert(union_ranges(t[le_zero][i], t[gt_zero][i]) == \ - t[unknown][i]); \ - assert(union_ranges(t[eq_zero][i], t[ne_zero][i]) == \ - t[unknown][i]); \ + assert(union_ranges(t[lt_zero][i], t[ge_zero][i]) == \ + t[unknown][i]); \ + assert(union_ranges(t[le_zero][i], t[gt_zero][i]) == \ + t[unknown][i]); \ + assert(union_ranges(t[eq_zero][i], t[ne_zero][i]) == \ + t[unknown][i]); \ + } \ } \ } while (false) |