[llvm-bugs] [Bug 39568] New: partial loop-unswitch infers wrong values for conditions with multiple invariants

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Nov 6 04:34:32 PST 2018


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

            Bug ID: 39568
           Summary: partial loop-unswitch infers wrong values for
                    conditions with multiple invariants
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: Loop Optimizer
          Assignee: unassignedbugs at nondot.org
          Reporter: fedor.v.sergeev at gmail.com
                CC: llvm-bugs at lists.llvm.org

] cat partial-bad-unswitch.ll
define i32 @mainReduced(i8 %pre28, i8 %pr) {
entry:
  %entry_check = icmp slt i8 %pre28, 4
  %pr_zero = icmp ne i8 %pr, 0
  ; here with our arguments we have entry_check == false
  ; and pr_zero == true
  br label %loop
loop:
  %idx = phi i32 [ 1, %entry ], [ %idxplus, %loopexit ]
  ; by "partially" unswitching on (entry_check OR pr_zero) to be true
  ; we cant enforce BOTH to be true
  %idxcheck = icmp ne i32 %idx, 30
  %brmerge = or i1 %entry_check, %pr_zero
  %brmerge2 = or i1 %brmerge, %idxcheck
  br i1 %brmerge2, label %loopexit, label %deopt
loopexit:
  ; here we need to select second value
  ; YET partial unswitch replaces %entry_check with true
  %mux = select i1 %entry_check, i32 83, i32 0
  %idxplus = add nuw nsw i32 %idx, 1
  %check = icmp ugt i32 %idx, 241
  br i1 %check, label %return, label %loop

return:
  ret i32 %mux
deopt:
  unreachable
}

define i32 @main() {
  %res = call i32 @mainReduced(i8 20, i8 10) ; should calculate 0, not 83
  ret i32 %res
}
] bin/opt -loop-unswitch partial-bad-unswitch.ll | bin/lli; echo $?
0
] bin/opt -enable-nontrivial-unswitch -simple-loop-unswitch 
partial-bad-unswitch.ll | bin/lli; echo $?
83

83 is incorrect here. Simple-loop-unswitch leads to a miscompile.

-- 
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/20181106/e03f8cb7/attachment.html>


More information about the llvm-bugs mailing list