fix bug: consider (br (freeze undef)) as well defined
MODIFY
ir/instr.cpp
ir/instr.cpp
@@ -1629,7 +1629,7 @@ void Branch::print(ostream &os) const {
static pair<expr,expr> // <condition, not_undef>
jump_undef_condition(State &s, const Value &val, const expr &e) {
- if (isUndef(e))
+ if (s.isUndef(e))
return { expr::mkUInt(0, 1), false };
expr c, a, b, lhs, rhs, ty;
@@ -1637,7 +1637,7 @@ jump_undef_condition(State &s, const Value &val, const expr &e) {
uint64_t n;
// (ite (= ((_ extract 0 0) ty_%var) #b0) %var undef!0)
- if (e.isIf(c, a, b) && isUndef(b) && c.isEq(lhs, rhs)) {
+ if (e.isIf(c, a, b) && s.isUndef(b) && c.isEq(lhs, rhs)) {
if (lhs.isUInt(n))
swap(lhs, rhs);

MODIFY
ir/state.cpp
ir/state.cpp
@@ -104,6 +104,10 @@ const OrExpr* State::jumpCondFrom(const BasicBlock &bb) const {
return I == pres.end() ? nullptr : &I->second.first.path;
}
+bool State::isUndef(const expr &e) const {
+ return undef_vars.count(e) != 0;
+}
+
bool State::startBB(const BasicBlock &bb) {
assert(undef_vars.empty());
ENSURE(seen_bbs.emplace(&bb).second);

MODIFY
ir/state.h
ir/state.h
@@ -117,6 +117,7 @@ public:
const StateValue& getAndAddUndefs(const Value &val);
const ValTy& at(const Value &val) const;
const smt::OrExpr* jumpCondFrom(const BasicBlock &bb) const;
+ bool isUndef(const smt::expr &e) const;
bool startBB(const BasicBlock &bb);
void addJump(const BasicBlock &dst);

ADD
tests/alive-tv/br-undef3.srctgt.ll
+define i8 @src() {
+ %f = freeze i1 undef
+ br i1 %f, label %a, label %b
+
+a:
+ ret i8 0
+
+b:
+ ret i8 3
+}
+
+define i8 @tgt() {
+ unreachable
+}
+
+; ERROR: Source is more defined

fix bug: consider (br (freeze undef)) as well defined