[PATCH] D100464: [DSE] Remove stores in the same loop iteration

Nikita Popov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 16 13:24:16 PDT 2021


nikic requested changes to this revision.
nikic added a comment.
This revision now requires changes to proceed.

I believe this is still not quite correct. Consider the following variation:

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

The current implementation will eliminate store `store i16 2`.

The reason is that DSE determines eliminable stores in two phases: First, a dominating access for the killing store is found. And second, all uses of the dominating access are checked. When `store i16 1` is the killing access, we will bail out due to the loop invariance check. When `store i16 3` is the killing store, we will not, because they are in the same loop. The `store i16 1` will be examined as a use and skipped as a fully overwriting store.


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

https://reviews.llvm.org/D100464



More information about the llvm-commits mailing list