fix implement fast-math support for phi
MODIFY
ir/instr.cpp
ir/instr.cpp
@@ -2575,7 +2575,7 @@ void Phi::replace(const string &predecessor, Value &newval) {
}
void Phi::print(ostream &os) const {
- os << getName() << " = phi " << print_type(getType());
+ os << getName() << " = phi " << fmath << print_type(getType());
bool first = true;
for (auto &[val, bb] : values) {
@@ -2599,7 +2599,10 @@ StateValue Phi::toSMT(State &s) const {
ret.add(I->second, (*pre)());
}
}
- return *ret();
+
+ StateValue sv = *ret();
+ auto identity = [](const expr &x) { return x; };
+ return fm_poison(s, sv.value, sv.non_poison, identity, fmath, true);
}
expr Phi::getTypeConstraints(const Function &f) const {

MODIFY
ir/instr.h
ir/instr.h
@@ -418,8 +418,11 @@ public:
class Phi final : public Instr {
std::vector<std::pair<Value*, std::string>> values;
+ FastMathFlags fmath;
+
public:
- Phi(Type &type, std::string &&name) : Instr(type, std::move(name)) {}
+ Phi(Type &type, std::string &&name, FastMathFlags fmath = {})
+ : Instr(type, std::move(name)), fmath(fmath) {}
void addValue(Value &val, std::string &&BB_name);
void removeValue(const std::string &BB_name);

MODIFY
llvm_util/llvm2alive.cpp
llvm_util/llvm2alive.cpp
@@ -602,7 +602,7 @@ public:
if (!ty)
return error(i);
- auto phi = make_unique<Phi>(*ty, value_name(i));
+ auto phi = make_unique<Phi>(*ty, value_name(i), parse_fmath(i));
todo_phis.emplace_back(phi.get(), &i);
RETURN_IDENTIFIER(std::move(phi));
}

ADD
tests/alive-tv/fp/phi-nsz.srctgt.ll
+define float @src(float %a, float %b, float %c) {
+entry:
+ %t1 = fcmp oeq float %b, 0.0
+ br i1 %t1, label %bb1, label %bb3
+
+bb1:
+ %t2 = fcmp ogt float %c, %c
+ br i1 %t2, label %bb2, label %bb3
+
+bb2:
+ br label %bb3
+
+bb3:
+ %t4 = phi nsz float [ %a, %entry ], [ %b, %bb1 ], [ %c, %bb2 ]
+ ret float %t4
+}
+
+define float @tgt(float %a, float %b, float %c) {
+ %t1 = fcmp oeq float %b, 0.000000
+ %t4 = select nsz i1 %t1, float %b, float %a
+ ret float %t4
+}

fix #793: implement fast-math support for phi