[LLVMbugs] [Bug 17133] New: missing SCEV support for xor in loops

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Fri Sep 6 13:48:34 PDT 2013


http://llvm.org/bugs/show_bug.cgi?id=17133

            Bug ID: 17133
           Summary: missing SCEV support for xor in loops
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: Scalar Optimizations
          Assignee: unassignedbugs at nondot.org
          Reporter: richard-llvm at metafoo.co.uk
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

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.

-- 
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/20130906/8d3eda19/attachment.html>


More information about the llvm-bugs mailing list