[PATCH] D60021: InstSimplify: Fold round intrinsics from sitofp
Roman Lebedev via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sat Mar 30 01:49:59 PDT 2019
lebedev.ri added a comment.
In D60021#1448785 <https://reviews.llvm.org/D60021#1448785>, @lebedev.ri wrote:
> Do we not need any fast math flags here?
>
> https://llvm.org/docs/LangRef.html#id276
>
> The ‘sitofp’ instruction interprets its operand as a signed integer quantity
> and converts it to the corresponding floating-point value. If the value cannot
> be exactly represented, it is rounded using the default rounding mode.
>
Right, *rounded*.
#include <math.h>
#include <limits>
#include <cassert>
static bool test(int x) {
float f = x;
float i;
float fract = modff(f, &i);
return fract == 0.0;
}
int main() {
for(size_t i = 0; i <= std::numeric_limits<unsigned int>::max(); i++)
assert(test(int(i)));
return 0;
}
agrees.
Might also want to fold
%conv.i = sitofp i32 %conv1 to float
%call.i = call float @modff(float %conv.i, float* nonnull %i.i) #4
%cmp.i = fcmp oeq float %call.i, 0.000000e+00
=>
%cmp.i = true
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D60021/new/
https://reviews.llvm.org/D60021
More information about the llvm-commits
mailing list