[llvm-bugs] [Bug 24743] New: SimplifyCFG may de-optimize code with highly predictable branches

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Sep 7 13:18:58 PDT 2015


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

            Bug ID: 24743
           Summary: SimplifyCFG may de-optimize code with highly
                    predictable branches
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: Transformation Utilities
          Assignee: unassignedbugs at nondot.org
          Reporter: spatel+llvm at rotateright.com
                CC: llvm-bugs at lists.llvm.org
    Classification: Unclassified

As mentioned in:
https://llvm.org/bugs/show_bug.cgi?id=23827#c7
SimplifyCFG (eg, FoldBranchToCommonDest()) transforms code based on a static
"BonusInstThreshold". This can waste time because this change in the CFG may
later be undone in CodeGenPrepare::splitBranchCondition() or
SelectionDAGBuilder::visitBr().

Without external information (target hook, profile data, or programmer hint) to
justify the transform, SimplifyCFG shouldn't be doing this:

$ cat predictable_branches.ll 
define void @x_or_y(i32 %x, i32 %y) #0 {
entry:
  %cmp = icmp slt i32 %x, 3
  br i1 %cmp, label %if.then, label %lhs.false

lhs.false:
  %cmp1 = icmp sgt i32 %y, 10
  br i1 %cmp1, label %if.then, label %end

if.then:  
  %call = call i32 (...) @foo() #2
  br label %end

end:  
  ret void
}

declare i32 @foo(...) #1

$ ./opt -simplifycfg predictable_branches.ll -S
define void @x_or_y(i32 %x, i32 %y) {
entry:
  %cmp = icmp slt i32 %x, 3
  %cmp1 = icmp sgt i32 %y, 10
  %or.cond = or i1 %cmp, %cmp1
  br i1 %or.cond, label %if.then, label %end

if.then:                              
  %call = call i32 (...) @foo()
  br label %end

end:  
  ret void
}

-- 
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/20150907/0127321c/attachment.html>


More information about the llvm-bugs mailing list