Skip to content

Commit 841aac0

Browse files
committedMar 25, 2018
[InstCombine] peek through more icmp of FP cast + bitcast
This is an extension of rL328426 as noted in D44367. llvm-svn: 328448
1 parent 48baeb0 commit 841aac0

File tree

2 files changed

+59
-139
lines changed

2 files changed

+59
-139
lines changed
 

‎llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp

+14-4
Original file line numberDiff line numberDiff line change
@@ -4506,13 +4506,23 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) {
45064506
return New;
45074507
}
45084508

4509-
// Sign-bit checks are preserved through signed floating-point casts:
4510-
// icmp slt (bitcast (sitofp X)), 0 --> icmp slt X, 0
4511-
// icmp sgt (bitcast (sitofp X)), -1 --> icmp sgt X, -1
4509+
// Zero-equality and sign-bit checks are preserved through sitofp + bitcast.
45124510
Value *X;
45134511
if (match(Op0, m_BitCast(m_SIToFP(m_Value(X))))) {
4514-
if (Pred == ICmpInst::ICMP_SLT && match(Op1, m_Zero()))
4512+
// icmp eq (bitcast (sitofp X)), 0 --> icmp eq X, 0
4513+
// icmp ne (bitcast (sitofp X)), 0 --> icmp ne X, 0
4514+
// icmp slt (bitcast (sitofp X)), 0 --> icmp slt X, 0
4515+
// icmp sgt (bitcast (sitofp X)), 0 --> icmp sgt X, 0
4516+
if ((Pred == ICmpInst::ICMP_EQ || Pred == ICmpInst::ICMP_SLT ||
4517+
Pred == ICmpInst::ICMP_NE || Pred == ICmpInst::ICMP_SGT) &&
4518+
match(Op1, m_Zero()))
45154519
return new ICmpInst(Pred, X, ConstantInt::getNullValue(X->getType()));
4520+
4521+
// icmp slt (bitcast (sitofp X)), 1 --> icmp slt X, 1
4522+
if (Pred == ICmpInst::ICMP_SLT && match(Op1, m_One()))
4523+
return new ICmpInst(Pred, X, ConstantInt::get(X->getType(), 1));
4524+
4525+
// icmp sgt (bitcast (sitofp X)), -1 --> icmp sgt X, -1
45164526
if (Pred == ICmpInst::ICMP_SGT && match(Op1, m_AllOnes()))
45174527
return new ICmpInst(Pred, X, ConstantInt::getAllOnesValue(X->getType()));
45184528
}

0 commit comments

Comments
 (0)