Revision c1885fc710ddebff3e50023e662e9f822a7f2a3d authored by Alexander Root on 04 December 2020, 00:14:07 UTC, committed by GitHub on 04 December 2020, 00:14:07 UTC
* Add shift_left fix for signed integers by possibly negative values + regression test * add required condition on shift_left integer fix * add type check to shift_left minimum condition * fix constant folding of shifts with |b| >= type.bits() for types that allow overflow (failes correctness/simplify test) * make regression tests use scoped bindings * change condition in case int24/int48 proposal happens soon * revert changes based on overflow expectations * add more regression tests * clarify comment * add shift_left min handler for b only UB * fix clang-tidy complaint * relax shift_left of non-negative value constraint * pull case outside of unnecessary preconditions * fix clang-format complaint * fix broken precondition * add typecheck to possibly save a can_prove() call * add easy-out type check to precondition * Add descriptive comment to bug fix + add another early-exit precondition Co-authored-by: Steven Johnson <srj@google.com>
1 parent 28f9aef
HexagonAlignment.h
#ifndef HALIDE_HEXAGON_ALIGNMENT_H
#define HALIDE_HEXAGON_ALIGNMENT_H
/** \file
* Class for analyzing Alignment of loads and stores for Hexagon.
*/
#include "IR.h"
namespace Halide {
namespace Internal {
// TODO: This class is barely stateful, and could probably be replaced with free functions.
class HexagonAlignmentAnalyzer {
const int required_alignment;
public:
HexagonAlignmentAnalyzer(int required_alignment)
: required_alignment(required_alignment) {
internal_assert(required_alignment != 0);
}
/** Analyze the index of a load/store instruction for alignment
* Returns true if it can determing that the address of the store or load is aligned, false otherwise.
*/
template<typename T>
bool is_aligned_impl(const T *op, int native_lanes, int64_t *aligned_offset) {
debug(3) << "HexagonAlignmentAnalyzer: Check if " << op->index << " is aligned to a "
<< required_alignment << " byte boundary\n"
<< "native_lanes: " << native_lanes << "\n";
Expr index = op->index;
const Ramp *ramp = index.as<Ramp>();
if (ramp) {
index = ramp->base;
} else if (index.type().is_vector()) {
debug(3) << "Is Unaligned\n";
return false;
}
internal_assert(native_lanes != 0) << "Type is larger than required alignment of " << required_alignment << " bytes\n";
// If this is a parameter, the base_alignment should be
// host_alignment. Otherwise, this is an internal buffer,
// which we assume has been aligned to the required alignment.
if (op->param.defined() && ((op->param.host_alignment() % required_alignment) != 0)) {
return false;
}
bool known_alignment = (op->alignment.modulus % native_lanes) == 0;
if (known_alignment) {
*aligned_offset = op->alignment.remainder % native_lanes;
}
return known_alignment && (*aligned_offset == 0);
}
bool is_aligned(const Load *op, int64_t *aligned_offset) {
int native_lanes = required_alignment / op->type.bytes();
return is_aligned_impl<Load>(op, native_lanes, aligned_offset);
}
bool is_aligned(const Store *op, int64_t *aligned_offset) {
int native_lanes = required_alignment / op->value.type().bytes();
return is_aligned_impl<Store>(op, native_lanes, aligned_offset);
}
};
} // namespace Internal
} // namespace Halide
#endif
![swh spinner](/static/img/swh-spinner.gif)
Computing file changes ...