add vector support to fcmp
MODIFY
ir/instr.cpp
ir/instr.cpp
@@ -1164,14 +1164,13 @@ StateValue ICmp::toSMT(State &s) const {
return { v.value.toBVBool(), a.non_poison && b.non_poison && v.non_poison };
};
- if (auto ret_agg = getType().getAsAggregateType()) {
- auto elem_agg = elem_ty.getAsAggregateType();
+ if (auto agg = elem_ty.getAsAggregateType()) {
vector<StateValue> vals;
- for (unsigned i = 0, e = elem_agg->numElementsConst(); i != e; ++i) {
- vals.emplace_back(scalar(elem_agg->extract(a_eval, i),
- elem_agg->extract(b_eval, i)));
+ for (unsigned i = 0, e = agg->numElementsConst(); i != e; ++i) {
+ vals.emplace_back(scalar(agg->extract(a_eval, i),
+ agg->extract(b_eval, i)));
}
- return ret_agg->aggregateVals(vals);
+ return getType().getAsAggregateType()->aggregateVals(vals);
}
return scalar(a_eval, b_eval);
}
@@ -1221,8 +1220,11 @@ void FCmp::print(ostream &os) const {
}
StateValue FCmp::toSMT(State &s) const {
- auto &[av, ap] = s[*a];
- auto &[bv, bp] = s[*b];
+ auto &a_eval = s[*a];
+ auto &b_eval = s[*b];
+
+ auto fn = [&](const auto &a, const auto &b) -> StateValue {
+ const expr &av = a.value, &bv = b.value;
expr val;
switch (cond) {
case OEQ: val = av.foeq(bv); break;
@@ -1240,13 +1242,24 @@ StateValue FCmp::toSMT(State &s) const {
case UNE: val = av.fune(bv); break;
case UNO: val = av.funo(bv); break;
}
- return { val.toBVBool(), ap && bp };
+ return { val.toBVBool(), a.non_poison && b.non_poison };
+ };
+
+ if (auto agg = a->getType().getAsAggregateType()) {
+ vector<StateValue> vals;
+ for (unsigned i = 0, e = agg->numElementsConst(); i != e; ++i) {
+ vals.emplace_back(fn(agg->extract(a_eval, i), agg->extract(b_eval, i)));
+ }
+ return getType().getAsAggregateType()->aggregateVals(vals);
+ }
+ return fn(a_eval, b_eval);
}
expr FCmp::getTypeConstraints(const Function &f) const {
return Value::getTypeConstraints() &&
- getType().enforceIntType(1) &&
- a->getType().enforceFloatType() &&
+ getType().enforceIntOrVectorType(1) &&
+ getType().enforceVectorTypeEquiv(a->getType()) &&
+ a->getType().enforceFloatOrVectorType() &&
a->getType() == b->getType();
}
@@ -1346,13 +1359,9 @@ StateValue Phi::toSMT(State &s) const {
if (!pre) // jump from unreachable BB
continue;
- auto v = s[*val];
- if (first) {
- ret = v;
+ auto &v = s[*val];
+ ret = first ? v : StateValue::mkIf(*pre, v, ret);
first = false;
- } else {
- ret = StateValue::mkIf(*pre, v, ret);
- }
}
return ret;
}
@@ -1469,17 +1478,17 @@ void Switch::print(ostream &os) const {
}
StateValue Switch::toSMT(State &s) const {
- auto val = s[*value];
+ auto &val = s[*value];
expr default_cond(true);
for (auto &[value_cond, bb] : targets) {
- auto target = s[*value_cond];
+ auto &target = s[*value_cond];
assert(target.non_poison.isTrue());
s.addJump({ val.value == target.value, expr(val.non_poison) }, bb);
default_cond &= val.value != target.value;
}
- s.addJump({ move(default_cond), move(val.non_poison) }, default_target);
+ s.addJump({ move(default_cond), expr(val.non_poison) }, default_target);
s.addUB(false);
return {};
}

MODIFY
llvm_util/llvm2alive.cpp
llvm_util/llvm2alive.cpp
@@ -257,15 +257,13 @@ public:
case llvm::CmpInst::FCMP_UNE: cond = FCmp::UNE; break;
case llvm::CmpInst::FCMP_UNO: cond = FCmp::UNO; break;
case llvm::CmpInst::FCMP_TRUE: {
- auto tru = get_operand(llvm::ConstantInt::getTrue(i.getContext()));
- RETURN_IDENTIFIER(make_unique<UnaryOp>(get_int_type(1),
- value_name(i), *tru,
+ auto tru = get_operand(llvm::ConstantInt::getTrue(i.getType()));
+ RETURN_IDENTIFIER(make_unique<UnaryOp>(*ty, value_name(i), *tru,
UnaryOp::Copy));
}
case llvm::CmpInst::FCMP_FALSE: {
- auto fals = get_operand(llvm::ConstantInt::getFalse(i.getContext()));
- RETURN_IDENTIFIER(make_unique<UnaryOp>(get_int_type(1),
- value_name(i), *fals,
+ auto fals = get_operand(llvm::ConstantInt::getFalse(i.getType()));
+ RETURN_IDENTIFIER(make_unique<UnaryOp>(*ty, value_name(i), *fals,
UnaryOp::Copy));
}
default:
@@ -276,8 +274,7 @@ public:
if (i.getFastMathFlags().any())
return error(i);
- RETURN_IDENTIFIER(make_unique<FCmp>(get_int_type(1), value_name(i),
- cond, *a, *b));
+ RETURN_IDENTIFIER(make_unique<FCmp>(*ty, value_name(i), cond, *a, *b));
}
RetTy visitSelectInst(llvm::SelectInst &i) {

add vector support to fcmp