<div dir="ltr"><span style="font-size:12.8px">+ Constant *NullVal = ConstantInt::getNullValue(P-></span><wbr style="font-size:12.8px"><span style="font-size:12.8px">getType());</span><br style="font-size:12.8px"><span style="font-size:12.8px">+ Value *CmpP = Builder->CreateICmp(Pred, P, NullVal);</span><br style="font-size:12.8px"><span style="font-size:12.8px">+ Value *CmpQ = Builder->CreateICmp(Pred, Q, NullVal);</span><br><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">P and Q might not have equivalent pointer types. We really do need to get two calls to getNullValue here.</span></div><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">Caused a crash while building Chromium:</span></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Aug 17, 2016 at 9:30 AM, Sanjay Patel via llvm-commits <span dir="ltr"><<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: spatel<br>
Date: Wed Aug 17 11:30:43 2016<br>
New Revision: 278944<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=278944&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project?rev=278944&view=rev</a><br>
Log:<br>
[InstCombine] clean up foldICmpOrConstant(); NFCI<br>
<br>
1. Change variable names<br>
2. Use local variables to reduce code<br>
3. Use ? instead of if/else<br>
4. Use the APInt variable instead of 'RHS' so the removal of the FIXME code will be direct<br>
<br>
Modified:<br>
llvm/trunk/lib/Transforms/<wbr>InstCombine/<wbr>InstCombineCompares.cpp<br>
<br>
Modified: llvm/trunk/lib/Transforms/<wbr>InstCombine/<wbr>InstCombineCompares.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp?rev=278944&r1=278943&r2=278944&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/llvm/trunk/lib/<wbr>Transforms/InstCombine/<wbr>InstCombineCompares.cpp?rev=<wbr>278944&r1=278943&r2=278944&<wbr>view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- llvm/trunk/lib/Transforms/<wbr>InstCombine/<wbr>InstCombineCompares.cpp (original)<br>
+++ llvm/trunk/lib/Transforms/<wbr>InstCombine/<wbr>InstCombineCompares.cpp Wed Aug 17 11:30:43 2016<br>
@@ -1879,40 +1879,38 @@ Instruction *InstCombiner::foldICmpAndCo<br>
return nullptr;<br>
}<br>
<br>
-Instruction *InstCombiner::<wbr>foldICmpOrConstant(ICmpInst &ICI, Instruction *LHSI,<br>
- const APInt *RHSV) {<br>
+/// Fold icmp (or X, Y), C.<br>
+Instruction *InstCombiner::<wbr>foldICmpOrConstant(ICmpInst &Cmp, Instruction *Or,<br>
+ const APInt *C) {<br>
// FIXME: This check restricts all folds under here to scalar types.<br>
- ConstantInt *RHS = dyn_cast<ConstantInt>(ICI.<wbr>getOperand(1));<br>
+ ConstantInt *RHS = dyn_cast<ConstantInt>(Cmp.<wbr>getOperand(1));<br>
if (!RHS)<br>
return nullptr;<br>
<br>
- if (RHS->isOne()) {<br>
+ ICmpInst::Predicate Pred = Cmp.getPredicate();<br>
+ if (*C == 1) {<br>
// icmp slt signum(V) 1 --> icmp slt V, 1<br>
Value *V = nullptr;<br>
- if (ICI.getPredicate() == ICmpInst::ICMP_SLT &&<br>
- match(LHSI, m_Signum(m_Value(V))))<br>
+ if (Pred == ICmpInst::ICMP_SLT && match(Or, m_Signum(m_Value(V))))<br>
return new ICmpInst(ICmpInst::ICMP_SLT, V,<br>
ConstantInt::get(V->getType(), 1));<br>
}<br>
<br>
- if (!ICI.isEquality() || !RHS->isNullValue() || !LHSI->hasOneUse())<br>
+ if (!Cmp.isEquality() || *C != 0 || !Or->hasOneUse())<br>
return nullptr;<br>
<br>
Value *P, *Q;<br>
- if (match(LHSI, m_Or(m_PtrToInt(m_Value(P)), m_PtrToInt(m_Value(Q))))) {<br>
+ if (match(Or, m_Or(m_PtrToInt(m_Value(P)), m_PtrToInt(m_Value(Q))))) {<br>
// Simplify icmp eq (or (ptrtoint P), (ptrtoint Q)), 0<br>
// -> and (icmp eq P, null), (icmp eq Q, null).<br>
- Value *ICIP = Builder->CreateICmp(ICI.<wbr>getPredicate(), P,<br>
- Constant::getNullValue(P-><wbr>getType()));<br>
- Value *ICIQ = Builder->CreateICmp(ICI.<wbr>getPredicate(), Q,<br>
- Constant::getNullValue(Q-><wbr>getType()));<br>
- Instruction *Op;<br>
- if (ICI.getPredicate() == ICmpInst::ICMP_EQ)<br>
- Op = BinaryOperator::CreateAnd(<wbr>ICIP, ICIQ);<br>
- else<br>
- Op = BinaryOperator::CreateOr(ICIP, ICIQ);<br>
- return Op;<br>
+ Constant *NullVal = ConstantInt::getNullValue(P-><wbr>getType());<br>
+ Value *CmpP = Builder->CreateICmp(Pred, P, NullVal);<br>
+ Value *CmpQ = Builder->CreateICmp(Pred, Q, NullVal);<br>
+ auto LogicOpc = Pred == ICmpInst::Predicate::ICMP_EQ ? Instruction::And<br>
+ : Instruction::Or;<br>
+ return BinaryOperator::Create(<wbr>LogicOpc, CmpP, CmpQ);<br>
}<br>
+<br>
return nullptr;<br>
}<br>
<br>
<br>
<br>
______________________________<wbr>_________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br></div>