Skip to content

Commit 92bac4f

Browse files
committed
Revert "Add FMF support for fptrunc/fpext (AliveToolkit#1131)"
This reverts commit 9ffc75d.
1 parent f1dc1e9 commit 92bac4f

File tree

5 files changed

+32
-90
lines changed

5 files changed

+32
-90
lines changed

ir/instr.cpp

Lines changed: 30 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1713,9 +1713,9 @@ unique_ptr<Instr> ConversionOp::dup(Function &f, const string &suffix) const {
17131713

17141714
FpConversionOp::FpConversionOp(Type &type, std::string &&name, Value &val,
17151715
Op op, FpRoundingMode rm, FpExceptionMode ex,
1716-
unsigned flags, FastMathFlags fmath)
1716+
unsigned flags)
17171717
: Instr(type, std::move(name)), val(&val), op(op), rm(rm), ex(ex),
1718-
flags(flags), fmath(fmath) {
1718+
flags(flags) {
17191719
switch (op) {
17201720
case UIntToFP:
17211721
assert((flags & NNEG) == flags);
@@ -1724,14 +1724,6 @@ FpConversionOp::FpConversionOp(Type &type, std::string &&name, Value &val,
17241724
assert(flags == 0);
17251725
break;
17261726
}
1727-
switch (op) {
1728-
case FPTrunc:
1729-
case FPExt:
1730-
break;
1731-
default:
1732-
assert(fmath.isNone());
1733-
break;
1734-
}
17351727
}
17361728

17371729
vector<Value*> FpConversionOp::operands() const {
@@ -1768,8 +1760,6 @@ void FpConversionOp::print(ostream &os) const {
17681760
os << getName() << " = " << str;
17691761
if (flags & NNEG)
17701762
os << "nneg ";
1771-
if (!fmath.isNone())
1772-
os << fmath;
17731763
os << *val << print_type(getType(), " to ", "");
17741764
if (!rm.isDefault())
17751765
os << ", rounding=" << rm;
@@ -1779,8 +1769,7 @@ void FpConversionOp::print(ostream &os) const {
17791769

17801770
StateValue FpConversionOp::toSMT(State &s) const {
17811771
auto &v = s[*val];
1782-
function<StateValue(const expr &, const Type &, const expr &)> fn;
1783-
function<StateValue(const StateValue &, const Type &, const Type &)> scalar;
1772+
function<StateValue(const expr &, const Type &, const expr&)> fn;
17841773

17851774
switch (op) {
17861775
case SIntToFP:
@@ -1864,43 +1853,37 @@ StateValue FpConversionOp::toSMT(State &s) const {
18641853
break;
18651854
case FPExt:
18661855
case FPTrunc:
1867-
scalar = [&](const StateValue &sv, const Type &from_type,
1868-
const Type &to_type) -> StateValue {
1869-
auto fn = [&](auto &v, auto &rm) {
1870-
return v.float2Float(to_type.getAsFloatType()->getDummyFloat(), rm);
1871-
};
1872-
return fm_poison(s, sv.value, sv.non_poison, fn, from_type, fmath, rm,
1873-
false, false, &to_type);
1856+
fn = [](auto &val, auto &to_type, auto &rm) -> StateValue {
1857+
return { val.float2Float(to_type.getAsFloatType()->getDummyFloat(), rm),
1858+
true };
18741859
};
18751860
break;
18761861
}
18771862

1878-
if (!scalar)
1879-
scalar = [&](const StateValue &sv, const Type &from_type,
1880-
const Type &to_type) -> StateValue {
1881-
auto val = sv.value;
1863+
auto scalar = [&](const StateValue &sv, const Type &from_type,
1864+
const Type &to_type) -> StateValue {
1865+
auto val = sv.value;
18821866

1883-
if (from_type.isFloatType()) {
1884-
auto ty = from_type.getAsFloatType();
1885-
val = ty->getFloat(val);
1886-
}
1867+
if (from_type.isFloatType()) {
1868+
auto ty = from_type.getAsFloatType();
1869+
val = ty->getFloat(val);
1870+
}
18871871

1888-
function<StateValue(const expr &)> fn_rm = [&](auto &rm) {
1889-
return fn(val, to_type, rm);
1890-
};
1891-
AndExpr np;
1892-
np.add(sv.non_poison);
1893-
1894-
StateValue ret = to_type.isFloatType() ? round_value(s, rm, np, fn_rm)
1895-
: fn(val, to_type, rm.toSMT());
1896-
np.add(std::move(ret.non_poison));
1897-
1898-
return {to_type.isFloatType() ? to_type.getAsFloatType()->fromFloat(
1899-
s, ret.value, from_type,
1900-
from_type.isFloatType(), sv.value)
1901-
: std::move(ret.value),
1902-
np()};
1903-
};
1872+
function<StateValue(const expr&)> fn_rm
1873+
= [&](auto &rm) { return fn(val, to_type, rm); };
1874+
AndExpr np;
1875+
np.add(sv.non_poison);
1876+
1877+
StateValue ret = to_type.isFloatType() ? round_value(s, rm, np, fn_rm)
1878+
: fn(val, to_type, rm.toSMT());
1879+
np.add(std::move(ret.non_poison));
1880+
1881+
return { to_type.isFloatType()
1882+
? to_type.getAsFloatType()
1883+
->fromFloat(s, ret.value, from_type, from_type.isFloatType(),
1884+
sv.value)
1885+
: std::move(ret.value), np()};
1886+
};
19041887

19051888
if (getType().isVectorType()) {
19061889
vector<StateValue> vals;
@@ -1948,8 +1931,8 @@ expr FpConversionOp::getTypeConstraints(const Function &f) const {
19481931
}
19491932

19501933
unique_ptr<Instr> FpConversionOp::dup(Function &f, const string &suffix) const {
1951-
return make_unique<FpConversionOp>(getType(), getName() + suffix, *val, op,
1952-
rm, ex, flags, fmath);
1934+
return
1935+
make_unique<FpConversionOp>(getType(), getName() + suffix, *val, op, rm);
19531936
}
19541937

19551938

ir/instr.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -323,20 +323,16 @@ class FpConversionOp final : public Instr {
323323
FpRoundingMode rm;
324324
FpExceptionMode ex;
325325
unsigned flags;
326-
FastMathFlags fmath;
327326

328327
public:
329328
FpConversionOp(Type &type, std::string &&name, Value &val, Op op,
330329
FpRoundingMode rm = {}, FpExceptionMode ex = {},
331-
unsigned flags = None, FastMathFlags fmath = {});
330+
unsigned flags = None);
332331

333332
Op getOp() const { return op; }
334333
FpRoundingMode getRoundingMode() const { return rm; }
335334
FpExceptionMode getExceptionMode() const { return ex; }
336335
unsigned getFlags() const { return flags; }
337-
FastMathFlags getFastMathFlags() const {
338-
return fmath;
339-
}
340336

341337
std::vector<Value*> operands() const override;
342338
bool propagatesPoison() const override;

llvm_util/llvm2alive.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ class llvm2alive_ : public llvm::InstVisitor<llvm2alive_, unique_ptr<Instr>> {
318318
}
319319
return make_unique<FpConversionOp>(*ty, value_name(i), *val, op,
320320
FpRoundingMode{}, FpExceptionMode{},
321-
flags, parse_fmath(i));
321+
flags);
322322
}
323323

324324
RetTy visitFreezeInst(llvm::FreezeInst &i) {

tests/alive-tv/fp/fpext-trunc.srctgt.ll

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,3 @@ define half @src(half %0) {
77
define half @tgt(half %0) {
88
ret half %0
99
}
10-
11-
define half @src1(float noundef %a) {
12-
%b = fneg nnan float %a
13-
%c = fptrunc nnan float %b to half
14-
ret half %c
15-
}
16-
17-
define half @tgt1(float noundef %a) {
18-
%b = fptrunc nnan float %a to half
19-
%c = fneg nnan half %b
20-
ret half %c
21-
}
22-
23-
define half @src2(half noundef %a) {
24-
%av = fpext nnan half %a to float
25-
%c = fadd nnan float %av, %av
26-
%d = fptrunc nnan float %c to half
27-
ret half %d
28-
}
29-
30-
define half @tgt2(half noundef %a) {
31-
%b = fadd nnan half %a, %a
32-
ret half %b
33-
}

tests/alive-tv/fp/fptrunc-fmf-fail.srctgt.ll

Lines changed: 0 additions & 13 deletions
This file was deleted.

0 commit comments

Comments
 (0)