[llvm-bugs] [Bug 46939] New: SCEV: missed canonicalization ((-1 * (0 smin %n)) + %n) is actually just (0 smax %n)

via llvm-bugs llvm-bugs at lists.llvm.org
Fri Jul 31 10:15:33 PDT 2020


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

            Bug ID: 46939
           Summary: SCEV: missed canonicalization  ((-1 * (0 smin %n)) +
                    %n)  is actually just  (0 smax %n)
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Global Analyses
          Assignee: unassignedbugs at nondot.org
          Reporter: lebedev.ri at gmail.com
                CC: llvm-bugs at lists.llvm.org

I'm not really sure how SCEV canonicalization is performed, but
https://rise4fun.com/Alive/GsleR

; RUN: opt < %s -analyze -scalar-evolution | FileCheck %s

; FIXME: ((-1 * (0 smin %n)) + %n)  is actually just  (0 smax %n)

declare void @iteration()

define void @reverse_loop(i32 %n) {
; CHECK-LABEL: 'reverse_loop'
; CHECK-NEXT:  Classifying expressions for: @reverse_loop
; CHECK-NEXT:    %i.011 = phi i32 [ %n, %for.body.lr.ph ], [ %dec, %for.body ]
; CHECK-NEXT:    --> {%n,+,-1}<nsw><%for.body> U: full-set S: full-set Exits:
(0 smin %n) LoopDispositions: { %for.body: Computable }
; CHECK-NEXT:    %dec = add nsw i32 %i.011, -1
; CHECK-NEXT:    --> {(-1 + %n),+,-1}<nw><%for.body> U: full-set S: full-set
Exits: (-1 + (0 smin %n)) LoopDispositions: { %for.body: Computable }
; CHECK-NEXT:  Determining loop execution counts for: @reverse_loop
; CHECK-NEXT:  Loop %for.body: backedge-taken count is ((-1 * (0 smin %n)) +
%n)
; CHECK-NEXT:  Loop %for.body: max backedge-taken count is 2147483647
; CHECK-NEXT:  Loop %for.body: Predicated backedge-taken count is ((-1 * (0
smin %n)) + %n)
; CHECK-NEXT:   Predicates:
; CHECK:       Loop %for.body: Trip multiple is 1
;
entry:
  %cmp10 = icmp sgt i32 %n, -1
  br i1 %cmp10, label %for.body.lr.ph, label %for.cond.cleanup

for.body.lr.ph:
  br label %for.body

for.body:
  %i.011 = phi i32 [ %n, %for.body.lr.ph ], [ %dec, %for.body ]
  call void @iteration()
  %dec = add nsw i32 %i.011, -1
  %cmp = icmp sgt i32 %i.011, 0
  br i1 %cmp, label %for.body, label %for.cond.cleanup.loopexit

for.cond.cleanup.loopexit:
  br label %for.cond.cleanup

for.cond.cleanup:
  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/20200731/f20ba3ae/attachment.html>


More information about the llvm-bugs mailing list