[PATCH] D87163: [DSE] Switch to MemorySSA-backed DSE by default.

Mikael Holmén via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 14 00:18:52 PDT 2020


uabelho added a comment.

Hi,

I'm seeing what I think is a miscompile with this:

  opt -S -dse -o - dse.ll

on

  @x = global [10 x [10 x i16]] zeroinitializer, align 1
  
  define i16 @f() {
  entry:
    br label %do.body
  
  do.body:                                          ; preds = %if.end, %entry
    %i.0 = phi i16 [ 0, %entry ], [ %inc, %if.end ]
    %j.0 = phi i16 [ 0, %entry ], [ %add, %if.end ]
    %arrayidx2 = getelementptr inbounds [10 x [10 x i16]], [10 x [10 x i16]]* @x, i16 0, i16 %i.0, i16 %j.0
    store i16 2, i16* %arrayidx2, align 1
    %exitcond = icmp eq i16 %i.0, 4
    br i1 %exitcond, label %if.end10, label %if.end
  
  if.end:                                           ; preds = %do.body
    %inc = add nuw nsw i16 %i.0, 1
    %add = add nuw nsw i16 %j.0, 2
    br label %do.body
  
  if.end10:                                         ; preds = %do.body
    store i16 1, i16* %arrayidx2, align 1
    ret i16 0
  }

gives

  x = global [10 x [10 x i16]] zeroinitializer, align 1
  
  define i16 @f() {
  entry:
    br label %do.body
  
  do.body:                                          ; preds = %if.end, %entry
    %i.0 = phi i16 [ 0, %entry ], [ %inc, %if.end ]
    %j.0 = phi i16 [ 0, %entry ], [ %add, %if.end ]
    %arrayidx2 = getelementptr inbounds [10 x [10 x i16]], [10 x [10 x i16]]* @x, i16 0, i16 %i.0, i16 %j.0
    %exitcond = icmp eq i16 %i.0, 4
    br i1 %exitcond, label %if.end10, label %if.end
  
  if.end:                                           ; preds = %do.body
    %inc = add nuw nsw i16 %i.0, 1
    %add = add nuw nsw i16 %j.0, 2
    br label %do.body
  
  if.end10:                                         ; preds = %do.body
    store i16 1, i16* %arrayidx2, align 1
    ret i16 0
  }

So the store in the loop has been removed, which I think is incorrect.
The

  store i16 2

in the loop should be carried out at (i,j) == (0,0), (1,2), (2,4), (3,6) och (4,8) and then the last of them should be overwritten by the

  store i16 1

after the loop, but now the store in the loop is removed so we're only left with a written 1 at (4,8).


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87163/new/

https://reviews.llvm.org/D87163



More information about the llvm-commits mailing list