Skip to content

Commit

Permalink
Do not use bitwise OR on bool (#7459)
Browse files Browse the repository at this point in the history
This has unexpected semantics and can prevent optimizations. Note that
the current code still returns the correct results, so this is mostly a
cosmetic change.
  • Loading branch information
akuzm authored Nov 21, 2024
1 parent 399b11a commit f2663aa
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion tsl/src/compression/algorithms/dictionary.c
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ tsl_text_dictionary_decompress_all(Datum compressed, Oid element_type, MemoryCon
bool have_incorrect_index = false;
for (uint32 i = 0; i < n_notnull; i++)
{
have_incorrect_index |= indices[i] >= (int16) header->num_distinct;
have_incorrect_index = have_incorrect_index || indices[i] >= (int16) header->num_distinct;
}
CheckCompressedData(!have_incorrect_index);

Expand Down
4 changes: 2 additions & 2 deletions tsl/src/nodes/decompress_chunk/vector_predicates.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ get_vector_qual_summary(uint64 *restrict qual_result, size_t n_rows)
bool all_rows_pass = true;
for (size_t i = 0; i < n_rows / 64; i++)
{
any_rows_pass |= (qual_result[i] != 0);
all_rows_pass &= (~qual_result[i] == 0);
any_rows_pass = any_rows_pass || (qual_result[i] != 0);
all_rows_pass = all_rows_pass && (~qual_result[i] == 0);
}

if (n_rows % 64 != 0)
Expand Down
4 changes: 2 additions & 2 deletions tsl/src/nodes/vector_agg/function/int24_sum_single.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ FUNCTION_NAME(vector_impl)(void *agg_state, int n, const CTYPE *values, const ui
{
const bool row_ok = arrow_row_is_valid(filter, row);
batch_sum += values[row] * row_ok;
have_result |= row_ok;
have_result = have_result || row_ok;
}

if (unlikely(pg_add_s64_overflow(state->result, batch_sum, &state->result)))
Expand All @@ -48,7 +48,7 @@ FUNCTION_NAME(vector_impl)(void *agg_state, int n, const CTYPE *values, const ui
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE), errmsg("bigint out of range")));
}

state->isvalid |= have_result;
state->isvalid = state->isvalid || have_result;
}

static pg_attribute_always_inline void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ FUNCTION_NAME(vector_impl)(void *agg_state, int n, const CTYPE *values, const ui
isnan((double) new_value));

outer_result = do_replace ? new_value : outer_result;
outer_isvalid |= do_replace;
outer_isvalid = outer_isvalid || do_replace;
}

state->isvalid = outer_isvalid;
Expand Down
6 changes: 3 additions & 3 deletions tsl/src/nodes/vector_agg/function/sum_float_single.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ FUNCTION_NAME(vector_impl)(void *agg_state, int n, const CTYPE *values, const ui
} u = { .f = values[row] }; \
u.m &= row_valid ? ~(MASKTYPE) 0 : (MASKTYPE) 0; \
*dest += u.f; \
*have_result |= row_valid;
*have_result = *have_result || row_valid;

INNER_LOOP
}
Expand All @@ -71,13 +71,13 @@ FUNCTION_NAME(vector_impl)(void *agg_state, int n, const CTYPE *values, const ui
for (int i = 1; i < UNROLL_SIZE; i++)
{
sum_accu[0] += sum_accu[i];
have_result_accu[0] |= have_result_accu[i];
have_result_accu[0] = have_result_accu[0] || have_result_accu[i];
}
#undef UNROLL_SIZE
#undef INNER_LOOP

FloatSumState *state = (FloatSumState *) agg_state;
state->isvalid |= have_result_accu[0];
state->isvalid = state->isvalid || have_result_accu[0];
state->result += sum_accu[0];
}

Expand Down

0 comments on commit f2663aa

Please sign in to comment.