[llvm-bugs] [Bug 48583] New: Wrong answer after loop vectorization

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Dec 23 05:15:37 PST 2020


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

            Bug ID: 48583
           Summary: Wrong answer after loop vectorization
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Backend: AArch64
          Assignee: unassignedbugs at nondot.org
          Reporter: guopeilin1 at huawei.com
                CC: arnaud.degrandmaison at arm.com,
                    llvm-bugs at lists.llvm.org, smithp352 at googlemail.com,
                    Ties.Stuij at arm.com

This test case get the wrong answer after loop vectorization
====== commands =======
opt -loop-vectorize before-loop-vec.ll -o after-loop-vec.ll -S
llc after-loop-vec.ll -filetype=obj -o tmp.o
clang tmp.o -o tmp.out

========================
actually the test case's main job is doing a "361804 >> 18"
However the result shows that we finally get result 0 rather than 1, which is 
a totally wrong answer

===== result =========
tmp.out: test-case.cpp:16: int main(): Assertion `a!=0 && "a should be 1"'
failed.
Aborted (core dumped)


===== before-loop-vec.ll ==========
target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
target triple = "aarch64-unknown-linux-gnu"

@a = dso_local local_unnamed_addr global i8 0, align 4
@b = dso_local local_unnamed_addr global [384 x i64] zeroinitializer, align 8
@c = dso_local local_unnamed_addr global i32 0, align 4
@.str.1 = private unnamed_addr constant [24 x i8] c"a!=0 && \22a should be
1\22\00", align 1
@.str.2 = private unnamed_addr constant [14 x i8] c"test-case.cpp\00", align 1
@__PRETTY_FUNCTION__.main = private unnamed_addr constant [11 x i8] c"int
main()\00", align 1

; Function Attrs: nofree norecurse nounwind
define dso_local void @_Z1dii(i32 %e, i32 %f) local_unnamed_addr {
entry:
  br label %for.cond

for.cond:                                         ; preds = %for.cond.cleanup5,
%entry
  %g.0 = phi i32 [ 0, %entry ], [ %add11, %for.cond.cleanup5 ]
  %cmp = icmp ult i32 %g.0, 11
  br i1 %cmp, label %for.cond1.preheader, label %for.cond.cleanup

for.cond1.preheader:                              ; preds = %for.cond
  %conv3 = and i32 %e, 255
  %cmp417 = icmp ugt i32 %conv3, 0
  br i1 %cmp417, label %for.body6.lr.ph, label %for.cond.cleanup5

for.body6.lr.ph:                                  ; preds =
%for.cond1.preheader
  br label %for.body6

for.cond.cleanup:                                 ; preds = %for.cond
  ret void

for.cond1.for.cond.cleanup5_crit_edge:            ; preds = %for.inc
  br label %for.cond.cleanup5

for.cond.cleanup5:                                ; preds =
%for.cond1.for.cond.cleanup5_crit_edge, %for.cond1.preheader
  %add11 = add nuw nsw i32 %g.0, 2
  br label %for.cond

for.body6:                                        ; preds = %for.body6.lr.ph,
%for.inc
  %h.018 = phi i8 [ 0, %for.body6.lr.ph ], [ %add, %for.inc ]
  %0 = load i32, i32* @c, align 4
  %tobool = icmp eq i32 %0, -1
  br i1 %tobool, label %for.inc, label %if.then

if.then:                                          ; preds = %for.body6
  %1 = lshr i32 %f, 18
  %conv7 = trunc i32 %1 to i8
  store i8 %conv7, i8* @a, align 4
  %idxprom = zext i8 %h.018 to i64
  %arrayidx = getelementptr inbounds [384 x i64], [384 x i64]* @b, i64 0, i64
%idxprom
  store i64 0, i64* %arrayidx, align 8
  br label %for.inc

for.inc:                                          ; preds = %for.body6,
%if.then
  %add = add i8 %h.018, 3
  %conv = zext i8 %add to i32
  %cmp4 = icmp ugt i32 %conv3, %conv
  br i1 %cmp4, label %for.body6, label %for.cond1.for.cond.cleanup5_crit_edge,
!llvm.loop !9
}

; Function Attrs: norecurse nounwind
define dso_local i32 @main() local_unnamed_addr {
entry:
  call void @_Z1dii(i32 78, i32 361804)
  %0 = load i8, i8* @a, align 4
  %cmp = icmp eq i8 %0, 0
  br i1 %cmp, label %cond.false, label %cond.end

cond.false:                                       ; preds = %entry
  call void @__assert_fail(i8* getelementptr inbounds ([24 x i8], [24 x i8]*
@.str.1, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]*
@.str.2, i64 0, i64 0), i32 16, i8* getelementptr inbounds ([11 x i8], [11 x
i8]* @__PRETTY_FUNCTION__.main, i64 0, i64 0))
  unreachable

cond.end:                                         ; preds = %entry
  ret i32 0
}

; Function Attrs: noreturn nounwind
declare dso_local void @__assert_fail(i8*, i8*, i32, i8*) local_unnamed_addr

!9 = distinct !{!9, !10, !11}
!10 = !{!"llvm.loop.vectorize.predicate.enable", i1 true}
!11 = !{!"llvm.loop.vectorize.enable", i1 true}

-- 
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/20201223/6dcea32e/attachment-0001.html>


More information about the llvm-bugs mailing list