GVN Hoist moving a store across load

Hi,

I have a scenario, roughly like this:

   if (...) {
     ... = *x
     *x = 0
   } else {
     ... = *x
     *x = 0
   }

The two sides are functionally different, but both load some value and then set it to 0.

After GVN Hoist, I get:

   *x = 0
   if (...) {
     ... = *x
   } else {
     ... = *x
   }

That is, the store was hoisted above the loads.

The code is not exactly public, so I can't just attach it as a testcase, but it seems like some simple check is missing somewhere.

Does this ring a bell?

-Krzysztof

Is the aliasing correct? Check the LHS type with type of x to see that they are properly aliased.

-Kevin

Opened https://llvm.org/bugs/show_bug.cgi?id=28874 for this.

-Krzysztof

From what i can tell (just diffing before/after) , this is caused by the same iterator bug and should be fixed in a moment by https://reviews.llvm.org/D23187

This patch fixes the original application. In the testcase, a load is hoisted instead of the store.

Thanks!

-Krzysztof