<html>
<head>
<base href="https://bugs.llvm.org/">
</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 - [SimplifyCFG] ValueTracking should support icmps fed by 'and'"
href="https://bugs.llvm.org/show_bug.cgi?id=33611">33611</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>[SimplifyCFG] ValueTracking should support icmps fed by 'and'
</td>
</tr>
<tr>
<th>Product</th>
<td>libraries
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Windows NT
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>enhancement
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>Scalar Optimizations
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>mcrosier@codeaurora.org
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>--- C test case ---
void foo(void);
void bar(void);
void test(unsigned *a, unsigned *b) {
if (a && b) {
bar();
if (a == 0)
foo();
}
}
--- IR test case ---
declare void @foo()
declare void @bar()
define void @test(i32* %a, i32* %b) local_unnamed_addr #0 {
entry:
%tobool = icmp ne i32* %a, null
%tobool1 = icmp ne i32* %b, null
%or.cond = and i1 %tobool, %tobool1
br i1 %or.cond, label %if.then, label %if.end3
if.then: ; preds = %entry
call void @bar() #2
%cmp = icmp eq i32* %a, null
br i1 %cmp, label %if.then2, label %if.end3
if.then2: ; preds = %if.then
call void @foo() #2
br label %if.end3
if.end3: ; preds = %if.then,
%if.then2, %entry
ret void
}
--------------------
In the above test case, SimplifyCFG should be able to prove that '%cmp = icmp
eq i32* %a, null' is false based on a dominating condition and in turn convert
'br i1 %cmp, label %if.then2, label %if.end3' to an unconditional branch to
if.end3.
To catch this case, isImpliedCondition() in ValueTracking.cpp needs to support
icmps that are fed by 'and' instructions. Something similar to:
-----
if (!InvertAPred && match(LHS, m_And(m_Value(ALHS), m_Value(ARHS)))) {
if (Optional<bool> Implication = isImpliedCondition(ALHS, RHS, DL,
InvertAPred, Depth, AC, CxtI, DT))
return Implication;
if (Optional<bool> Implication = isImpliedCondition(ARHS, RHS, DL,
InvertAPred, Depth, AC, CxtI, DT))
return Implication;
return None;
}
-----
This case is handled in JumpThreading, but catching this case in SimplifyCFG
may reduce compile-time.</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>