<html>
    <head>
      <base href="https://llvm.org/bugs/" />
    </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 --- - Constant store not optimized out of the loop"
   href="https://llvm.org/bugs/show_bug.cgi?id=28097">28097</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Constant store not optimized out of the loop
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libraries
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>3.8
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </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>yyc1992@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>In the following IR, there are only one store and one load in the loop.
The store has a constant address and constant value and is always executed
before the load so it should be fine to move it outside the loop even if the
load and the store can alias. However, `opt` does not do this optimization at
any optimization level.

```
; ModuleID = 'c.ll'
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

; Function Attrs: norecurse nounwind
define double @julia_mysum_simd2_64926(double** nocapture %slot, i64 %len,
double* %ptr) #0 {
top:
  br label %if22

if22:                                             ; preds = %if22, %top
  %i = phi i64 [ %3, %if22 ], [ 0, %top ]
  %s.128 = phi double [ %2, %if22 ], [ 0.000000e+00, %top ]
  store double* %ptr, double** %slot, align 8, !tbaa !0,
!llvm.mem.parallel_loop_access !3
  %0 = getelementptr double, double* %ptr, i64 %i
  %1 = load double, double* %0, align 8, !llvm.mem.parallel_loop_access !3
  %2 = fadd fast double %1, %s.128
  %3 = add nuw nsw i64 %i, 1, !simd_loop !5
  %exitcond = icmp eq i64 %3, %len
  br i1 %exitcond, label %L18, label %if22, !llvm.loop !4

L18:                                              ; preds = %if22
  %.lcssa = phi double [ %2, %if22 ]
  ret double %.lcssa
}

attributes #0 = { norecurse nounwind }

!0 = !{!1, !1, i64 0}
!1 = !{!"jtbaa_gcframe", !2}
!2 = !{!"jtbaa"}
!3 = !{!4}
!4 = distinct !{!4}
!5 = !{}
```</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>