https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90269

            Bug ID: 90269
           Summary: loop distribution defeated by clobbers
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: enhancement
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: glisse at gcc dot gnu.org
  Target Milestone: ---

#include <memory>
#ifndef EASY
typedef std::unique_ptr<int> T;
#else
typedef int* T;
#endif
void f(T*__restrict a,T*__restrict b){
    for(int i=0;i<1024;++i){
        new(a+i)T(std::move(b[i]));
        b[i].~T();
    }
}

Compiling with -O3, with -DEASY I get a nice call to memcpy, while without it I
keep a loop. The difference, before the ldist pass, is that the version with
unique_ptr has clobbers:

  _8 = MEM[(int * const &)_3];
  MEM[(struct  &)_10] ={v} {CLOBBER};
  MEM[(struct _Head_base *)_10]._M_head_impl = _8;
  MEM[(struct  &)_3] ={v} {CLOBBER};

ldist checks gimple_has_side_effects (stmt) on the first clobber and gives up.
Vectorization does not seem to have any problem with those clobbers.

(by the way, I believe DSE could remove the first clobber, it seems pretty
useless when it is immediately followed by a write to the full object)

Reply via email to