[llvm-bugs] [Bug 32396] New: [LV] Miscompile caused due to incorrect index for extracting vector result

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Mar 23 08:48:00 PDT 2017


https://bugs.llvm.org/show_bug.cgi?id=32396

            Bug ID: 32396
           Summary: [LV] Miscompile caused due to incorrect index for
                    extracting vector result
           Product: new-bugs
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: new bugs
          Assignee: unassignedbugs at nondot.org
          Reporter: anna at azul.com
                CC: llvm-bugs at lists.llvm.org

Loop vectorizer extracts incorrect result from the vector.
Source code snippet:
int byres = 52, i=1;
for (i1 = 141; i1 < 170; i1++) {
            i2 = 193;
            while (--i2 > 0) {

                byRes = (((i) * i)); 
                i = i1 + i2; 
            }   
        }   
printf("%d", byRes);

Here byRes should be (169 + 2) ^ 2, i.e. i2 = 2 and i1 = 169

After vectorization of inner loop, byRes becomes (169 + 1) ^ 2, i.e. i2 = 1.

In the vectorized code, I've verified that the incorrect result comes about by
extracting from the incorrect index.
vector.ph:                                        ; preds = %min.iters.checked
  %broadcast.splatinsert = insertelement <16 x i32> undef, i32 %local_4_, i32 0
  %broadcast.splat = shufflevector <16 x i32> %broadcast.splatinsert, <16 x
i32> undef, <16 x i32> zeroinitializer
...
 br label %vector.body

vector.body:
 %vec.ind = phi <16 x i32> [ <i32 192, i32 191, i32 190, i32 189, i32 188, i32
187, i32 186, i32 185, i32 184, i32 183, i32 182, i32 181, i32 180, i32 179,
i32 178, i32 177>, %vector.ph ], [ %vec.ind.next, %vector.body ]
....
 %16 = add nuw nsw <16 x i32> %vec.ind, %broadcast.splat
 %vec.ind.next = add <16 x i32> %vec.ind, <i32 -16, i32 -16, i32 -16, i32 -16,
i32 -16, i32 -16, i32 -16, i32 -16, i32 -16, i32 -16, i32 -16, i32 -16, i32
-16, i32 -16, i32 -16, i32 -16>
  %18 = icmp eq i32 %index.next, 192 
  br i1 %18, label %middle.block, label %vector.body, !llvm.loop !0

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i32 192, 192 
  %vector.recur.extract = extractelement <16 x i32> %16, i32 15 

At index 15 from vector extract, we have i2 + i1 = 170, which is the incorrect
result to extract. The correct result is at index 14 (i2 + i1 = 171).

I'll attach the IR before vectorization and after vectorization.

Reproduce problem:
lli test.ll
29241

opt -loop-vectorize test.ll -S > test_after_vectorize.ll 2>&1
lli test_after_vectorize.ll 
28900

-- 
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/20170323/48ab1da9/attachment.html>


More information about the llvm-bugs mailing list