<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 --- - missing SCEV support for xor in loops"
   href="http://llvm.org/bugs/show_bug.cgi?id=17133">17133</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>missing SCEV support for xor in loops
          </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>Scalar Optimizations
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>richard-llvm@metafoo.co.uk
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvmbugs@cs.uiuc.edu
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>int x; void f() { for (int n = 0; n < 500000000; ++n) x ^= 1; }


With -O3 -fno-vectorize, we produce

define void @_Z1fv() #0 {
  %x.promoted = load i32* @x, align 4, !tbaa !0
  br label %1

; <label>:1                                       ; preds = %1, %0
  %2 = phi i32 [ %x.promoted, %0 ], [ %3, %1 ]
  %n.01 = phi i32 [ 0, %0 ], [ %4, %1 ]
  %3 = xor i32 %2, 1
  %4 = add nsw i32 %n.01, 1
  %exitcond = icmp eq i32 %4, 500000000
  br i1 %exitcond, label %5, label %1

; <label>:5                                       ; preds = %1
  store i32 %3, i32* @x, align 4, !tbaa !0
  ret void
}

With -O3 -fvectorize, we produce

define void @_Z1fv() #0 {
vector.ph:
  %x.promoted = load i32* @x, align 4, !tbaa !0
  %0 = insertelement <4 x i32> <i32 undef, i32 0, i32 0, i32 0>, i32
%x.promoted, i32 0
  br label %vector.body

vector.body:                                      ; preds = %vector.body,
%vector.ph
  %index = phi i32 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %vec.phi = phi <4 x i32> [ %0, %vector.ph ], [ %1, %vector.body ]
  %vec.phi2 = phi <4 x i32> [ zeroinitializer, %vector.ph ], [ %2, %vector.body
]
  %1 = xor <4 x i32> %vec.phi, <i32 1, i32 1, i32 1, i32 1>
  %2 = xor <4 x i32> %vec.phi2, <i32 1, i32 1, i32 1, i32 1>
  %index.next = add i32 %index, 8
  %3 = icmp eq i32 %index.next, 500000000
  br i1 %3, label %middle.block, label %vector.body

middle.block:                                     ; preds = %vector.body
  %bin.rdx = xor <4 x i32> %2, %1
  %rdx.shuf = shufflevector <4 x i32> %bin.rdx, <4 x i32> undef, <4 x i32> <i32
2, i32 3, i32 undef, i32 undef>
  %bin.rdx5 = xor <4 x i32> %bin.rdx, %rdx.shuf
  %rdx.shuf6 = shufflevector <4 x i32> %bin.rdx5, <4 x i32> undef, <4 x i32>
<i32 1, i32 undef, i32 undef, i32 undef>
  %bin.rdx7 = xor <4 x i32> %bin.rdx5, %rdx.shuf6
  %4 = extractelement <4 x i32> %bin.rdx7, i32 0
  store i32 %4, i32* @x, align 4, !tbaa !0
  ret void
}

This is a success for the vectorizer but a failure for LLVM as a whole. SCEV
should be able to determine that 'x' is unchanged by this loop and we should be
able to remove it.</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>