<html>
    <head>
      <base href="http://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 --- - [SLP] SLP cost model changes when operands are commuted."
   href="http://llvm.org/bugs/show_bug.cgi?id=20234">20234</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>[SLP] SLP cost model changes when operands are commuted.
          </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>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>mcrosier@codeaurora.org
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>aschwaighofer@apple.com, chandlerc@gmail.com, hfinkel@anl.gov, llvmbugs@cs.uiuc.edu, nrotem@apple.com
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>While modifying the reassociation pass I noticed the ordering of operands
changes the result computed by the SLP cost model.

Specifically, if the operands of 

  %add = fadd fast float %mul11, %mul12

are commuted

  %add = fadd fast float %mul12, %mul11

then the straight line code is not vectorized.  See below.

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

$> more test.ll
target datalayout = "e-m:e-i64:64-i128:128-n32:64-S128"
target triple = "aarch64--linux-gnu"

%structA = type { [2 x float] }

define void @good(%structA* nocapture readonly %J, i32 %xmin, i32 %ymin) {
entry:
  br label %for.body3.lr.ph

for.body3.lr.ph:
  %conv5 = sitofp i32 %ymin to float
  %conv = sitofp i32 %xmin to float
  %arrayidx4 = getelementptr inbounds %structA* %J, i64 0, i32 0, i64 0
  %0 = load float* %arrayidx4, align 4
  %sub = fsub fast float %conv, %0
  %arrayidx9 = getelementptr inbounds %structA* %J, i64 0, i32 0, i64 1
  %1 = load float* %arrayidx9, align 4
  %sub10 = fsub fast float %conv5, %1
  %mul11 = fmul fast float %sub, %sub
  %mul12 = fmul fast float %sub10, %sub10
  %add = fadd fast float %mul11, %mul12
  %cmp = fcmp oeq float %add, 0.000000e+00
  br i1 %cmp, label %for.body3.lr.ph, label %for.end27

for.end27:
  ret void
}

define void @bad(%structA* nocapture readonly %J, i32 %xmin, i32 %ymin) {
entry:
  br label %for.body3.lr.ph

for.body3.lr.ph:
  %conv5 = sitofp i32 %ymin to float
  %conv = sitofp i32 %xmin to float
  %arrayidx4 = getelementptr inbounds %structA* %J, i64 0, i32 0, i64 0
  %0 = load float* %arrayidx4, align 4
  %sub = fsub fast float %conv, %0
  %arrayidx9 = getelementptr inbounds %structA* %J, i64 0, i32 0, i64 1
  %1 = load float* %arrayidx9, align 4
  %sub10 = fsub fast float %conv5, %1
  %mul11 = fmul fast float %sub, %sub
  %mul12 = fmul fast float %sub10, %sub10
  %add = fadd fast float %mul12, %mul11         ;;;<---- Operands commuted!!
  %cmp = fcmp oeq float %add, 0.000000e+00
  br i1 %cmp, label %for.body3.lr.ph, label %for.end27

for.end27:
  ret void
}

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

$> opt -slp-vectorizer test.ll -S

; ModuleID = '/prj/llvm-arm/home/mrosier/15096/test.ll'
target datalayout = "e-m:e-i64:64-i128:128-n32:64-S128"
target triple = "aarch64--linux-gnu"

%structA = type { [2 x float] }

define void @good(%structA* nocapture readonly %J, i32 %xmin, i32 %ymin) {
entry:
  %0 = insertelement <2 x i32> undef, i32 %xmin, i32 0
  %1 = insertelement <2 x i32> %0, i32 %ymin, i32 1
  br label %for.body3.lr.ph

for.body3.lr.ph:                                  ; preds = %for.body3.lr.ph,
%entry
  %2 = sitofp <2 x i32> %1 to <2 x float>
  %arrayidx4 = getelementptr inbounds %structA* %J, i64 0, i32 0, i64 0
  %arrayidx9 = getelementptr inbounds %structA* %J, i64 0, i32 0, i64 1
  %3 = bitcast float* %arrayidx4 to <2 x float>*
  %4 = load <2 x float>* %3, align 4
  %5 = fsub <2 x float> %2, %4
  %6 = fmul <2 x float> %5, %5
  %7 = extractelement <2 x float> %6, i32 0
  %8 = extractelement <2 x float> %6, i32 1
  %add = fadd fast float %7, %8
  %cmp = fcmp oeq float %add, 0.000000e+00
  br i1 %cmp, label %for.body3.lr.ph, label %for.end27

for.end27:                                        ; preds = %for.body3.lr.ph
  ret void
}

define void @bad(%structA* nocapture readonly %J, i32 %xmin, i32 %ymin) {
entry:
  br label %for.body3.lr.ph

for.body3.lr.ph:                                  ; preds = %for.body3.lr.ph,
%entry
  %conv5 = sitofp i32 %ymin to float
  %conv = sitofp i32 %xmin to float
  %arrayidx4 = getelementptr inbounds %structA* %J, i64 0, i32 0, i64 0
  %0 = load float* %arrayidx4, align 4
  %sub = fsub fast float %conv, %0
  %arrayidx9 = getelementptr inbounds %structA* %J, i64 0, i32 0, i64 1
  %1 = load float* %arrayidx9, align 4
  %sub10 = fsub fast float %conv5, %1
  %mul11 = fmul fast float %sub, %sub
  %mul12 = fmul fast float %sub10, %sub10
  %add = fadd fast float %mul12, %mul11
  %cmp = fcmp oeq float %add, 0.000000e+00
  br i1 %cmp, label %for.body3.lr.ph, label %for.end27

for.end27:                                        ; preds = %for.body3.lr.ph
  ret void
}

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

I know nothing about the cost model, but I imagine commuting the operands
shouldn't have such an effect.</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>