summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms
diff options
context:
space:
mode:
authorSanjay Patel <spatel@rotateright.com>2018-03-24 15:45:02 +0000
committerSanjay Patel <spatel@rotateright.com>2018-03-24 15:45:02 +0000
commit745a9c62c2aeda93346d207809209e4770aff729 (patch)
tree46f49296dc69d6a93b04c6327a445c5576780155 /llvm/lib/Transforms
parent286074e8a16b550ff240754d10b7034f5c16ed90 (diff)
downloadbcm5719-llvm-745a9c62c2aeda93346d207809209e4770aff729.tar.gz
bcm5719-llvm-745a9c62c2aeda93346d207809209e4770aff729.zip
[InstCombine] peek through FP casts for sign-bit compares (PR36682)
This pattern came up in PR36682: https://bugs.llvm.org/show_bug.cgi?id=36682 https://godbolt.org/g/LhuD9A Equality checks are planned as a follow-up enhancement. Differential Revision: https://reviews.llvm.org/D44367 llvm-svn: 328426
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r--llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp9
1 files changed, 9 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
index 12894b7833b..61e1d928a99 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
@@ -4506,7 +4506,16 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) {
return New;
}
+ // Sign-bit checks are preserved through signed floating-point casts:
+ // icmp slt (bitcast (sitofp X)), 0 --> icmp slt X, 0
+ // icmp sgt (bitcast (sitofp X)), -1 --> icmp sgt X, -1
Value *X;
+ if (match(Op0, m_BitCast(m_SIToFP(m_Value(X))))) {
+ if (Pred == ICmpInst::ICMP_SLT && match(Op1, m_Zero()))
+ return new ICmpInst(Pred, X, ConstantInt::getNullValue(X->getType()));
+ if (Pred == ICmpInst::ICMP_SGT && match(Op1, m_AllOnes()))
+ return new ICmpInst(Pred, X, ConstantInt::getAllOnesValue(X->getType()));
+ }
// Zero-equality checks are preserved through unsigned floating-point casts:
// icmp eq (bitcast (uitofp X)), 0 --> icmp eq X, 0
OpenPOWER on IntegriCloud