Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions ir/value.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,18 +211,19 @@ string Input::getSMTName(unsigned child) const {
return smt_name;
}

StateValue Input::mkInput(State &s, const Type &ty, unsigned child) const {
StateValue Input::mkInput(State &s, const Type &ty, unsigned &next_child) const {
if (auto agg = ty.getAsAggregateType()) {
vector<StateValue> vals;
for (unsigned i = 0, e = agg->numElementsConst(); i < e; ++i) {
if (agg->isPadding(i))
continue;
auto name = getSMTName(child + i);
vals.emplace_back(mkInput(s, agg->getChild(i), child + i));
vals.emplace_back(mkInput(s, agg->getChild(i), next_child));
}
return agg->aggregateVals(vals);
}

// Number non-padding scalar leaves in depth-first order.
unsigned child = next_child++;
expr val;
if (hasAttribute(ParamAttrs::ByVal)) {
unsigned bid;
Expand Down Expand Up @@ -275,7 +276,8 @@ bool Input::isUndefMask(const expr &e) {
}

StateValue Input::toSMT(State &s) const {
return mkInput(s, getType(), 0);
unsigned next_child = 0;
return mkInput(s, getType(), next_child);
}

void Input::merge(const ParamAttrs &other) {
Expand Down
2 changes: 1 addition & 1 deletion ir/value.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ class Input final : public Value {
std::string smt_name;
ParamAttrs attrs;
std::string getSMTName(unsigned child) const;
StateValue mkInput(State &s, const Type &ty, unsigned child) const;
StateValue mkInput(State &s, const Type &ty, unsigned &next_child) const;
public:
Input(Type &type, std::string &&name);
void setAttributes(ParamAttrs &&new_attrs);
Expand Down
16 changes: 16 additions & 0 deletions tests/alive-tv/aggregate-input-poison.srctgt.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
; TEST-ARGS: -disable-undef-input
; ERROR: Target is more poisonous than source

define i32 @src({ <2 x i32>, <2 x i32> } %x) {
%a = extractvalue { <2 x i32>, <2 x i32> } %x, 0
%v = extractelement <2 x i32> %a, i32 1
%r = mul i32 %v, 0
ret i32 %r
}

define i32 @tgt({ <2 x i32>, <2 x i32> } %x) {
%a = extractvalue { <2 x i32>, <2 x i32> } %x, 1
%v = extractelement <2 x i32> %a, i32 0
%r = mul i32 %v, 0
ret i32 %r
}
17 changes: 17 additions & 0 deletions tests/alive-tv/aggregate-input-undef.srctgt.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
; TEST-ARGS: -disable-poison-input
; ERROR: Target's return value is more undefined

; Include an empty aggregate and alignment padding before the nested array.
%T = type { {}, i8, [2 x <2 x i32>] }

define i32 @src(%T %x) {
%a = extractvalue %T %x, 2, 0
%v = extractelement <2 x i32> %a, i32 1
ret i32 %v
}

define i32 @tgt(%T %x) {
%a = extractvalue %T %x, 2, 1
%v = extractelement <2 x i32> %a, i32 0
ret i32 %v
}
13 changes: 13 additions & 0 deletions tests/alive-tv/aggregate-input-value.srctgt.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
; ERROR: Value mismatch

define i32 @src({ <2 x i32>, <2 x i32> } noundef %x) {
%a = extractvalue { <2 x i32>, <2 x i32> } %x, 0
%v = extractelement <2 x i32> %a, i32 1
ret i32 %v
}

define i32 @tgt({ <2 x i32>, <2 x i32> } noundef %x) {
%a = extractvalue { <2 x i32>, <2 x i32> } %x, 1
%v = extractelement <2 x i32> %a, i32 0
ret i32 %v
}
2 changes: 2 additions & 0 deletions tests/unit/vector/scalablevector1.opt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
; TEST-ARGS: -disable-undef-input

Name: scalable vector add - identity
%r = add <vscale x 2 x i4> %a, %b
=>
Expand Down
32 changes: 22 additions & 10 deletions tools/transform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,11 @@ static void print_single_varval(ostream &os, State &st, const Model &m,
}
}

void tools::print_model_val(ostream &os, State &st, const Model &m,
const Value *var, const Type &type,
const StateValue &val, unsigned child) {
static void print_model_val_impl(ostream &os, State &st, const Model &m,
const Value *var, const Type &type,
const StateValue &val, unsigned &next_child) {
if (!type.isAggregateType()) {
print_single_varval(os, st, m, var, type, val, child);
print_single_varval(os, st, m, var, type, val, next_child++);
return;
}

Expand All @@ -103,12 +103,20 @@ void tools::print_model_val(ostream &os, State &st, const Model &m,
for (unsigned i = 0, e = agg->numElementsConst(); i < e; ++i) {
if (i != 0)
os << ", ";
tools::print_model_val(os, st, m, var, agg->getChild(i),
agg->extract(val, i), child + i);
unsigned padding_child = 0;
print_model_val_impl(os, st, m, agg->isPadding(i) ? nullptr : var,
agg->getChild(i), agg->extract(val, i),
agg->isPadding(i) ? padding_child : next_child);
}
os << (type.isStructType() ? " }" : " >");
}

void tools::print_model_val(ostream &os, State &st, const Model &m,
const Value *var, const Type &type,
const StateValue &val, unsigned child) {
print_model_val_impl(os, st, m, var, type, val, child);
}


using print_var_val_ty = function<void(ostream&, const Model&)>;

Expand Down Expand Up @@ -363,15 +371,17 @@ static bool error(Errors &errs, State &src_state, State &tgt_state,


static void instantiate_undef(const Input *in, map<expr, expr> &instances,
const Type &ty, unsigned child) {
const Type &ty, unsigned &next_child) {
if (auto agg = ty.getAsAggregateType()) {
for (unsigned i = 0, e = agg->numElementsConst(); i < e; ++i) {
if (!agg->isPadding(i))
instantiate_undef(in, instances, agg->getChild(i), child + i);
instantiate_undef(in, instances, agg->getChild(i), next_child);
}
return;
}

unsigned child = next_child++;

// Bail out if it gets too big. It's unlikely we can solve it anyway.
if (instances.size() >= 128 || hit_half_memory_limit())
return;
Expand Down Expand Up @@ -450,8 +460,10 @@ static expr preprocess(const Transform &t, const set<expr> &qvars0,
map<expr, expr> instances({ { std::move(e), true } });

for (auto &i : t.src.getInputs()) {
if (auto in = dynamic_cast<const Input*>(&i))
instantiate_undef(in, instances, i.getType(), 0);
if (auto in = dynamic_cast<const Input*>(&i)) {
unsigned next_child = 0;
instantiate_undef(in, instances, i.getType(), next_child);
}
}

expr insts(false);
Expand Down
Loading