<html>
<head>
<base href="https://llvm.org/bugs/" />
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW --- - Problem in InstCombineSelect.cpp handling SPF_ABS/SPF_NABS"
href="https://llvm.org/bugs/show_bug.cgi?id=25745">25745</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Problem in InstCombineSelect.cpp handling SPF_ABS/SPF_NABS
</td>
</tr>
<tr>
<th>Product</th>
<td>new-bugs
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>All
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>new bugs
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>cvick@codeaurora.org
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>In InstCombineSelect.cpp, visitSelectInst calls matchSelectPattern. If you
have a signed integer compare to a constant 0 or 1, matchSelectPattern returns
the flavor of SPF_ABS or SPF_NABS. Then in the subsequent call to
getCmpPredicateForMinMax, those values are not handled, and you hit an
unreachable.
InstCombineSelect 1288,1297 (in visitSelectInst)
Value *LHS, *RHS, *LHS2, *RHS2;
Instruction::CastOps CastOp;
SelectPatternResult SPR = matchSelectPattern(&SI, LHS, RHS, &CastOp);
auto SPF = SPR.Flavor;
if (SPF) {
// Canonicalize so that type casts are outside select patterns.
if (LHS->getType()->getPrimitiveSizeInBits() !=
SI.getType()->getPrimitiveSizeInBits()) {
CmpInst::Predicate Pred = getCmpPredicateForMinMax(SPF, SPR.Ordered);
InstCombineSelect 49,68
static CmpInst::Predicate getCmpPredicateForMinMax(SelectPatternFlavor SPF,
bool Ordered=false) {
switch (SPF) {
default:
llvm_unreachable("unhandled!");
case SPF_SMIN:
return ICmpInst::ICMP_SLT;
case SPF_UMIN:
return ICmpInst::ICMP_ULT;
case SPF_SMAX:
return ICmpInst::ICMP_SGT;
case SPF_UMAX:
return ICmpInst::ICMP_UGT;
case SPF_FMINNUM:
return Ordered ? FCmpInst::FCMP_OLT : FCmpInst::FCMP_ULT;
case SPF_FMAXNUM:
return Ordered ? FCmpInst::FCMP_OGT : FCmpInst::FCMP_UGT;
}
}
ValueTracking.cpp 3960,3987 (in MatchSelectPattern)
if (ConstantInt *C1 = dyn_cast<ConstantInt>(CmpRHS)) {
if ((CmpLHS == TrueVal && match(FalseVal, m_Neg(m_Specific(CmpLHS)))) ||
(CmpLHS == FalseVal && match(TrueVal, m_Neg(m_Specific(CmpLHS))))) {
// ABS(X) ==> (X >s 0) ? X : -X and (X >s -1) ? X : -X
// NABS(X) ==> (X >s 0) ? -X : X and (X >s -1) ? -X : X
if (Pred == ICmpInst::ICMP_SGT && (C1->isZero() || C1->isMinusOne())) {
return {(CmpLHS == TrueVal) ? SPF_ABS : SPF_NABS, SPNB_NA, false};
}
// ABS(X) ==> (X <s 0) ? -X : X and (X <s 1) ? -X : X
// NABS(X) ==> (X <s 0) ? X : -X and (X <s 1) ? X : -X
if (Pred == ICmpInst::ICMP_SLT && (C1->isZero() || C1->isOne())) {
return {(CmpLHS == FalseVal) ? SPF_ABS : SPF_NABS, SPNB_NA, false};
}
}
// Y >s C ? ~Y : ~C == ~Y <s ~C ? ~Y : ~C = SMIN(~Y, ~C)
if (const auto *C2 = dyn_cast<ConstantInt>(FalseVal)) {
if (C1->getType() == C2->getType() && ~C1->getValue() == C2->getValue() &&
(match(TrueVal, m_Not(m_Specific(CmpLHS))) ||
match(CmpLHS, m_Not(m_Specific(TrueVal))))) {
LHS = TrueVal;
RHS = FalseVal;
return {SPF_SMIN, SPNB_NA, false};
}
}
}</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>