[PATCH] D42879: InstCombine: 1./x >= 0. -> x >= 0.
Matthias Braun via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Feb 2 21:15:10 PST 2018
MatzeB created this revision.
MatzeB added reviewers: majnemer, spatel, arsenm, craig.topper, nlopes.
Herald added subscribers: wdng, mcrosier.
This adds the following two rules when the "no infs" fast-math
flag is set:
fcmp ninf pred (fdiv ninf 1., x), 0 -> fcmp pred x, 0
fcmp ninf pred (fdiv ninf -1., x), 0 -> fcmp swap(pred) x, 0
To justify the first rule:
- All of the following cases show that with or without fdiv the sign is the same and 0 does not occur.
- fdiv 1., small number <-> + large number or +inf on overflow
- fidv 1., -small number <-> - large number or -inf on overflow
- fdiv 1., big number <-> + small normal or denormal number (Example: 1./FLT_MAX = 1./0x0x1.fffffep+127 = 0x1p-128)
- fdiv 1., big number <-> - small normal or denormal number
NaN is preserved:
- fdiv 1., nan <-> nan
- fdiv 1., -nan <-> -nan
The following cases do not work correctly:
- fdiv 1., 0 <-> inf
- fdiv 1., -0 <-> -inf
- fdiv 1., inf </-> 0
- fdiv 1., -inf </-> -0
However having a "no inf" fast-math flag on the fcmp and the fdiv allows
us to ignore these cases.
The 2nd rule can be shown to be a variant of the first:
fcmp pred (fdiv -1., x), 0 -> fcmp pred fneg (fdiv 1., x), 0
-> fcmp swap(pred) (fdiv 1., x), 0 -> fcmp swap(pred) x, 0
Question to reviewers: Is it correct to assume that with `fcmp ninf (fdiv 1.0, x)` the input to fcmp cannot be +/- infinity and hence x cannot be +/- 0?
Repository:
rL LLVM
https://reviews.llvm.org/D42879
Files:
lib/Transforms/InstCombine/InstCombineCompares.cpp
test/Transforms/InstCombine/fcmp_reciproc.ll
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D42879.132725.patch
Type: text/x-patch
Size: 7631 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180203/045271fc/attachment.bin>
More information about the llvm-commits
mailing list