fix fp2[su]int poison condition
the existing condition would create ints that are not representable in floats
and therefore the condition would miss a few corner cases
Test case by Sanjay Patel
MODIFY
ir/instr.cpp
ir/instr.cpp
@@ -1260,18 +1260,16 @@ StateValue ConversionOp::toSMT(State &s) const {
break;
case FPToSInt:
fn = [](auto &&val, auto &to_type) -> StateValue {
- return { val.fp2sint(to_type.bits()),
- val.foge(expr::IntSMin(to_type.bits()).sint2fp(val)) &&
- val.fole(expr::IntSMax(to_type.bits()).sint2fp(val)) &&
- !val.isInf() };
+ expr bv = val.fp2sint(to_type.bits());
+ expr fp2 = bv.sint2fp(val);
+ return { move(bv), fp2 == val };
};
break;
case FPToUInt:
fn = [](auto &&val, auto &to_type) -> StateValue {
- return { val.fp2uint(to_type.bits()),
- val.foge(expr::mkFloat(0, val)) &&
- val.fole(expr::IntUMax(to_type.bits()).uint2fp(val)) &&
- !val.isInf() };
+ expr bv = val.fp2uint(to_type.bits());
+ expr fp2 = bv.uint2fp(val);
+ return { move(bv), fp2 == val };
};
break;
case FPExt:

RENAME
tests/alive-tv/fabs-2.srctgt.ll
tests/alive-tv/fp/fabs-2.srctgt.ll
RENAME
tests/alive-tv/fabs-fmf.srctgt.ll
tests/alive-tv/fp/fabs-fmf.srctgt.ll
RENAME
tests/alive-tv/fabs-libcall.srctgt.ll
tests/alive-tv/fp/fabs-libcall.srctgt.ll
RENAME
tests/alive-tv/fabs.srctgt.ll
tests/alive-tv/fp/fabs.srctgt.ll
RENAME
tests/alive-tv/fp128.srctgt.ll
tests/alive-tv/fp/fp128.srctgt.ll
RENAME
tests/alive-tv/fpround.srctgt.ll
tests/alive-tv/fp/fpround.srctgt.ll
ADD
tests/alive-tv/fp/fptoui.srctgt.ll
+; https://reviews.llvm.org/D89697
+
+define i32 @src(float %f) {
+ %r = fptoui float %f to i32
+ ret i32 %r
+}
+
+define i32 @tgt(float %f) {
+ %reduced = fsub float %f, 2147483648.0
+ %reduced_int = fptosi float %reduced to i32
+ %big = or i32 %reduced_int, 2147483648
+ %small = fptosi float %f to i32
+ %is_big = fcmp oge float %f, 2147483648.0
+ %r = select i1 %is_big, i32 %big, i32 %small
+ ret i32 %r
+}

fix fp2[su]int poison condition
the existing condition would create ints that are not representable in floats
and therefore the condition would miss a few corner cases
Test case by Sanjay Patel