[llvm-bugs] [Bug 45927] New: Incorrect MemorySSA result after LICM

via llvm-bugs llvm-bugs at lists.llvm.org
Thu May 14 05:24:22 PDT 2020


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

            Bug ID: 45927
           Summary: Incorrect MemorySSA result after LICM
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: Loop Optimizer
          Assignee: unassignedbugs at nondot.org
          Reporter: mattias.v.eriksson at ericsson.com
                CC: llvm-bugs at lists.llvm.org

I was debugging a wrong-code bug and think it is caused by LICM incorrectly
saying it preserves MemorySSA.

input.ll:
@a = external dso_local global i16, align 1
@c = external dso_local global i16, align 1

define dso_local void @main() {
entry:
  %res.addr.i = alloca i16, align 1
  br label %for.cond.i

for.cond.i:                                       ; preds = %f.exit.i, %entry
  %0 = load i16, i16* @c, align 1
  %inc.i = add nsw i16 %0, 1
  store i16 %inc.i, i16* @c, align 1
  br i1 false, label %f.exit.thread.i, label %f.exit.i

f.exit.thread.i:                                  ; preds = %for.cond.i
  store i16 1, i16* @a, align 1
  br label %g.exit

f.exit.i:                                         ; preds = %for.cond.i
  br i1 false, label %g.exit, label %for.cond.i

g.exit:                                           ; preds = %f.exit.i,
%f.exit.thread.i
  %1 = load i16, i16* @c, align 1
  store i16 %1, i16* %res.addr.i, align 1
  ret void
}


$ opt -O0 -licm -early-cse-memssa -S -o - input.ll
@a = external dso_local global i16, align 1
@c = external dso_local global i16, align 1

define dso_local void @main() {
entry:
  %res.addr.i = alloca i16, align 1
  %c.promoted = load i16, i16* @c, align 1
  br label %for.cond.i

for.cond.i:                                       ; preds = %f.exit.i, %entry
  %inc.i1 = phi i16 [ %inc.i, %f.exit.i ], [ %c.promoted, %entry ]
  %inc.i = add nsw i16 %inc.i1, 1
  br i1 false, label %f.exit.thread.i, label %f.exit.i

f.exit.thread.i:                                  ; preds = %for.cond.i
  store i16 %inc.i, i16* @c, align 1
  store i16 1, i16* @a, align 1
  br label %g.exit

f.exit.i:                                         ; preds = %for.cond.i
  br i1 false, label %g.exit.loopexit, label %for.cond.i

g.exit.loopexit:                                  ; preds = %f.exit.i
  store i16 %inc.i, i16* @c, align 1
  br label %g.exit

g.exit:                                           ; preds = %g.exit.loopexit,
%f.exit.thread.i
  store i16 %c.promoted, i16* %res.addr.i, align 1
  ret void
}

The store to %res.addr.i now incorrectly stores the entry value of @c from
%c.promoted.


If I run -licm and -early-cse-memssa in separate opt processes correct code is
generated:
$ opt -O0 -licm -o - input.ll | opt -O0 -early-cse-memssa -S -o -
@a = external dso_local global i16, align 1
@c = external dso_local global i16, align 1

define dso_local void @main() {
entry:
  %res.addr.i = alloca i16, align 1
  %c.promoted = load i16, i16* @c, align 1
  br label %for.cond.i

for.cond.i:                                       ; preds = %f.exit.i, %entry
  %inc.i1 = phi i16 [ %inc.i, %f.exit.i ], [ %c.promoted, %entry ]
  %inc.i = add nsw i16 %inc.i1, 1
  br i1 false, label %f.exit.thread.i, label %f.exit.i

f.exit.thread.i:                                  ; preds = %for.cond.i
  store i16 %inc.i, i16* @c, align 1
  store i16 1, i16* @a, align 1
  br label %g.exit

f.exit.i:                                         ; preds = %for.cond.i
  br i1 false, label %g.exit.loopexit, label %for.cond.i

g.exit.loopexit:                                  ; preds = %f.exit.i
  store i16 %inc.i, i16* @c, align 1
  br label %g.exit

g.exit:                                           ; preds = %g.exit.loopexit,
%f.exit.thread.i
  %0 = load i16, i16* @c, align 1
  store i16 %0, i16* %res.addr.i, align 1
  ret void
}

It also works when I remove
      AU.addPreserved<MemorySSAWrapperPass>();
from LegacyLICMPass::getAnalysisUsage()

-- 
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/20200514/54137a3a/attachment.html>


More information about the llvm-bugs mailing list