[llvm-bugs] [Bug 43540] New: Miscompile with opt -licm with memory-ssa enabled

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Oct 3 00:47:44 PDT 2019


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

            Bug ID: 43540
           Summary: Miscompile with opt -licm with memory-ssa enabled
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Loop Optimizer
          Assignee: unassignedbugs at nondot.org
          Reporter: mikael.holmen at ericsson.com
                CC: llvm-bugs at lists.llvm.org

Created attachment 22622
  --> https://bugs.llvm.org/attachment.cgi?id=22622&action=edit
bbi-33452.ll reproducer

With 

 opt -licm -S -o - bbi-33452.ll

the store to @v_2 is erroneously hoisted out of the loop, so it's done before
the memcpy reading from @v_2.

The loop is only run one round, so the hoisting looks wrong to me.

Input:

define void @foo() {
entry:
  br label %for.cond

for.cond:                                         ; preds = %for.body, %entry
  %0 = phi i16 [ %inc, %for.body ], [ 0, %entry ]
  %cmp = icmp slt i16 %0, 1
  br i1 %cmp, label %for.body, label %for.end

for.body:                                         ; preds = %for.cond
  call void @llvm.memcpy.p0i8.p0i8.i64(i8* @v_1, i8 * @v_2, i64 1, i1 false)
  store i8 1, i8 * @v_2, align 1
  %inc = add nsw i16 %0, 1
  br label %for.cond

for.end:                                          ; preds = %for.cond
  ret void
}

Output:

@v_1 = global i8 0, align 1
@v_2 = global i8 0, align 1

define void @foo() {
entry:
  store i8 1, i8* @v_2, align 1
  br label %for.cond

for.cond:                                         ; preds = %for.body, %entry
  %0 = phi i16 [ %inc, %for.body ], [ 0, %entry ]
  %cmp = icmp slt i16 %0, 1
  br i1 %cmp, label %for.body, label %for.end

for.body:                                         ; preds = %for.cond
  call void @llvm.memcpy.p0i8.p0i8.i64(i8* @v_1, i8* @v_2, i64 1, i1 false)
  %inc = add nsw i16 %0, 1
  br label %for.cond

for.end:                                          ; preds = %for.cond
  ret void
}

; Function Attrs: argmemonly nounwind willreturn
declare void @llvm.memcpy.p0i8.p0i8.i64(i8* noalias nocapture writeonly, i8*
noalias nocapture readonly, i64, i1 immarg) #0

attributes #0 = { argmemonly nounwind willreturn }

-- 
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/20191003/1875b4a3/attachment.html>


More information about the llvm-bugs mailing list