add support for select w/ fast-math flags
MODIFY
ir/instr.cpp
ir/instr.cpp
@@ -1414,7 +1414,7 @@ void Select::rauw(const Value &what, Value &with) {
}
void Select::print(ostream &os) const {
- os << getName() << " = select " << *cond << ", " << *a << ", " << *b;
+ os << getName() << " = select " << fmath << *cond << ", " << *a << ", " << *b;
}
StateValue Select::toSMT(State &s) const {
@@ -1422,10 +1422,12 @@ StateValue Select::toSMT(State &s) const {
auto &av = s[*a];
auto &bv = s[*b];
- auto scalar = [](const auto &a, const auto &b, const auto &c) -> StateValue {
+ auto scalar = [&](const auto &a, const auto &b, const auto &c) {
auto cond = c.value == 1;
- return { expr::mkIf(cond, a.value, b.value),
- c.non_poison && expr::mkIf(cond, a.non_poison, b.non_poison) };
+ return fm_poison(s, a.value, c.non_poison, b.value,
+ expr::mkIf(cond, a.non_poison, b.non_poison),
+ [&](expr &a, expr &b) { return expr::mkIf(cond, a, b); },
+ fmath, false);
};
if (auto agg = getType().getAsAggregateType()) {
@@ -1446,6 +1448,7 @@ expr Select::getTypeConstraints(const Function &f) const {
return Value::getTypeConstraints() &&
cond->getType().enforceIntOrVectorType(1) &&
getType().enforceVectorTypeIff(cond->getType()) &&
+ (fmath.isNone() ? expr(true) : getType().enforceFloatOrVectorType()) &&
getType() == a->getType() &&
getType() == b->getType();
}

MODIFY
ir/instr.h
ir/instr.h
@@ -175,9 +175,11 @@ public:
class Select final : public Instr {
Value *cond, *a, *b;
+ FastMathFlags fmath;
public:
- Select(Type &type, std::string &&name, Value &cond, Value &a, Value &b)
- : Instr(type, std::move(name)), cond(&cond), a(&a), b(&b) {}
+ Select(Type &type, std::string &&name, Value &cond, Value &a, Value &b,
+ FastMathFlags fmath = {})
+ : Instr(type, std::move(name)), cond(&cond), a(&a), b(&b), fmath(fmath) {}
Value *getTrueValue() const { return a; }
Value *getFalseValue() const { return b; }

MODIFY
llvm_util/llvm2alive.cpp
llvm_util/llvm2alive.cpp
@@ -405,7 +405,8 @@ public:
RetTy visitSelectInst(llvm::SelectInst &i) {
PARSE_TRIOP();
- RETURN_IDENTIFIER(make_unique<Select>(*ty, value_name(i), *a, *b, *c));
+ RETURN_IDENTIFIER(make_unique<Select>(*ty, value_name(i), *a, *b, *c,
+ parse_fmath(i)));
}
RetTy visitExtractValueInst(llvm::ExtractValueInst &i) {

add support for select w/ fast-math flags