<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 - [LoopVectorize] fast-math-flags on fcmp are not propagated correctly"
   href="https://bugs.llvm.org/show_bug.cgi?id=35538">35538</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>[LoopVectorize] fast-math-flags on fcmp are not propagated correctly
          </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>All
          </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>Loop Optimizer
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>spatel+llvm@rotateright.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>This is the IR for the max loop in <a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - Vectorization improvement opportunity for max/min"
   href="show_bug.cgi?id=35284">bug 35284</a> when compiled with
-ffinite-math-only:

target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-apple-macosx10.13.0"

define float @test(float* nocapture readonly %a, i32 %N) #0 {
entry:
  %cmp12 = icmp sgt i32 %N, 0
  br i1 %cmp12, label %for.body.lr.ph, label %for.cond.cleanup

for.body.lr.ph:                       
  %wide.trip.count = zext i32 %N to i64
  br label %for.body

for.cond.cleanup:                         
  %max.0.lcssa = phi float [ -1.000000e+00, %entry ], [ %max.0., %for.body ]
  ret float %max.0.lcssa

for.body:    
  %indvars.iv = phi i64 [ 0, %for.body.lr.ph ], [ %indvars.iv.next, %for.body ]
  %max.013 = phi float [ -1.000000e+00, %for.body.lr.ph ], [ %max.0., %for.body
]
  %arrayidx = getelementptr inbounds float, float* %a, i64 %indvars.iv
  %0 = load float, float* %arrayidx, align 4, !tbaa !3
  %cmp1.inv = fcmp nnan ninf oge float %0, %max.013
  %max.0. = select i1 %cmp1.inv, float %0, float %max.013
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond, label %for.cond.cleanup, label %for.body
}

attributes #0 = { norecurse nounwind readonly ssp uwtable
"correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false"
"less-precise-fpmad"="false" "no-frame-pointer-elim"="true"
"no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="true"
"no-jump-tables"="false" "no-nans-fp-math"="true"
"no-signed-zeros-fp-math"="false" "no-trapping-math"="false"
"stack-protector-buffer-size"="8" "target-cpu"="penryn"
"target-features"="+cx16,+fxsr,+mmx,+sse,+sse2,+sse3,+sse4.1,+ssse3,+x87"
"unsafe-fp-math"="false" "use-soft-float"="false" }

!llvm.module.flags = !{!0, !1}
!llvm.ident = !{!2}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 7, !"PIC Level", i32 2}
!2 = !{!"clang version 6.0.0 (trunk 319684)"}
!3 = !{!4, !4, i64 0}
!4 = !{!"float", !5, i64 0}
!5 = !{!"omnipotent char", !6, i64 0}
!6 = !{!"Simple C/C++ TBAA"}

-------------------------------------------------------------------------------

$ ./opt -loop-vectorize 35284finite.ll -S | grep fast
  %rdx.minmax.cmp = fcmp fast ogt <4 x float> %11, %12
  %rdx.minmax.cmp4 = fcmp fast ogt <4 x float> %rdx.minmax.select, %rdx.shuf
  %rdx.minmax.cmp7 = fcmp fast ogt <4 x float> %rdx.minmax.select5, %rdx.shuf6


The vectorizer took one fcmp with only 'nnan ninf', and it got replicated to
'fast' sometimes...but not all the time:

$ ./opt -loop-vectorize 35284finite.ll -S | grep nnan
  %8 = fcmp nnan ninf oge <4 x float> %wide.load, %vec.phi
  %9 = fcmp nnan ninf oge <4 x float> %wide.load3, %vec.phi2
  %cmp1.inv = fcmp nnan ninf oge float %15, %max.013</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>