<commit_before>#include <sstream>
#include <algorithm>

#include "CodeGen_OpenCL_Dev.h"
#include "CodeGen_Internal.h"
#include "Debug.h"
#include "IROperator.h"
#include "IRMutator.h"

namespace Halide {
namespace Internal {

using std::ostringstream;
using std::string;
using std::vector;
using std::sort;

static ostringstream nil;

// OpenCL doesn't support vectors of bools, this mutator rewrites IR
// to use signed integer vectors instead. This means that all logical
// ops are re-written to be bitwise ops. This then requires that
// condition of select nodes be converted back to boolean (by
// comparing the rewritten expression with zero). The OpenCL C codegen
// then just omits (via peepholing) the extra conversion ops (casts,
// NE with zero, etc.) because OpenCL C's ops return/consume the types
// these conversions produce.
class EliminateBoolVectors : public IRMutator {
private:
    using IRMutator::visit;

    template <typename T>
    void visit_comparison(const T* op) {
        Expr a = mutate(op->a);
        Expr b = mutate(op->b);

        Type t = a.type();
        if (t.width > 1) {
            // To represent bool vectors, OpenCL uses vectors of signed
            // integers with the same width as the types being compared.
            t.code = Type::Int;
            expr = T::make(a, b);
            expr = Cast::make(t, expr);
        } else if (!a.same_as(op->a) || !b.same_as(op->b)) {
            expr = T::make(a, b);
        } else {
            expr = op;
        }
    }

    void visit(const EQ *op) { visit_comparison(op); }
    void visit(const NE *op) { visit_comparison(op); }
    void visit(const LT *op) { visit_comparison(op); }
    void visit(const LE *op) { visit_comparison(op); }
    void visit(const GT *op) { visit_comparison(op); }
    void visit(const GE *op) { visit_comparison(op); }

    template <typename T>
    void visit_logical_binop(const T* op, const std::string& bitwise_op) {
        Expr a = mutate(op->a);<commit_msg>Avoid constructing redundant comparison ops when eliminating bool vectors.<commit_after>#include <sstream>
#include <algorithm>

#include "CodeGen_OpenCL_Dev.h"
#include "CodeGen_Internal.h"
#include "Debug.h"
#include "IROperator.h"
#include "IRMutator.h"

namespace Halide {
namespace Internal {

using std::ostringstream;
using std::string;
using std::vector;
using std::sort;

static ostringstream nil;

// OpenCL doesn't support vectors of bools, this mutator rewrites IR
// to use signed integer vectors instead. This means that all logical
// ops are re-written to be bitwise ops. This then requires that
// condition of select nodes be converted back to boolean (by
// comparing the rewritten expression with zero). The OpenCL C codegen
// then just omits (via peepholing) the extra conversion ops (casts,
// NE with zero, etc.) because OpenCL C's ops return/consume the types
// these conversions produce.
class EliminateBoolVectors : public IRMutator {
private:
    using IRMutator::visit;

    template <typename T>
    void visit_comparison(const T* op) {
        Expr a = mutate(op->a);
        Expr b = mutate(op->b);
        if (!a.same_as(op->a) || !b.same_as(op->b)) {
            expr = T::make(a, b);
        } else {
            expr = op;
        }

        Type t = a.type();
        if (t.width > 1) {
            // To represent bool vectors, OpenCL uses vectors of signed
            // integers with the same width as the types being compared.
            t.code = Type::Int;
            expr = Cast::make(t, expr);
        }
    }

    void visit(const EQ *op) { visit_comparison(op); }
    void visit(const NE *op) { visit_comparison(op); }
    void visit(const LT *op) { visit_comparison(op); }
    void visit(const LE *op) { visit_comparison(op); }
    void visit(const GT *op) { visit_comparison(op); }
    void visit(const GE *op) { visit_comparison(op); }

    template <typename T>
    void visit_logical_binop(const T* op, const std::string& bitwise_op) {
        Expr a = mutate(op->a);
{'fraction_non_alphanumeric': 0.11410064773293473, 'fraction_numerical': 0.0004982561036372695, 'mean_word_length': 2.979187314172448, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2330434', 'n_tokens_mistral': 1271, 'n_tokens_neox': 1216, 'n_words': 425}