[llvm-bugs] [Bug 33611] New: [SimplifyCFG] ValueTracking should support icmps fed by 'and'

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Jun 27 07:42:04 PDT 2017


https://bugs.llvm.org/show_bug.cgi?id=33611

            Bug ID: 33611
           Summary: [SimplifyCFG] ValueTracking should support icmps fed
                    by 'and'
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Scalar Optimizations
          Assignee: unassignedbugs at nondot.org
          Reporter: mcrosier at codeaurora.org
                CC: llvm-bugs at lists.llvm.org

--- 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.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20170627/857e0f63/attachment-0001.html>


More information about the llvm-bugs mailing list