[PATCH] D51942: [InstCombine] Fold (C/x)>0 into x>0 if possible
Martin Elshuber via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 11 10:44:23 PDT 2018
marels created this revision.
marels added reviewers: john.brawn, majnemer.
Herald added a subscriber: llvm-commits.
This patch adds a simplification for floating point compares that
depend on the inversion of a variable. The comparison can be folded
such that it solely depends on the variable rather than the division.
E.g.:
foo(double x) {
double a = 1.0 / x;
if (a < 0) ...
}
>
=
foo(double x) {
double a = 1.0 / x;
if (x < 0) ...
}
The following conversion is applied if C!=0 where C is a compiler
known constant:
(C/x < 0)
(C*x < 0) ... multiply by x*x; Note: x*x > 0 (see Remark 2)
... divide by C
(x < 0) ... if C > 0
(x > 0) ... if C < 0
Remarks:
1. To avoid cases where x = NaN only the ordered predicates (ogt, olt, oge, ole) are folded.
2. The division requires the flag 'ninf' to be set. This also ensures there x!=0 can be assumed.
Assume x=0. We know C!=0 (by definition) and C!=inf ('ninf' is set). Therefore C/x=inf (IEEE754_2008.pdf 7.2 and 7.3). But, because 'ninf' is set, the compile can assume x!=0
3. To avoid cases where C/x == 0.0, 'ninf' has to be set for the fdiv and fcmp instruction.
4. To allow the multiplication by x*x 'arcp' and 'ninf' has to be set for the fdiv and fcmp instruction.
Repository:
rL LLVM
https://reviews.llvm.org/D51942
Files:
lib/Transforms/InstCombine/InstCombineCompares.cpp
test/Transforms/InstCombine/fcmp.ll
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D51942.164925.patch
Type: text/x-patch
Size: 8254 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180911/479fb75d/attachment.bin>
More information about the llvm-commits
mailing list