[PATCH] D95543: [GVN] Clobber partially aliased loads.

Daniil Fukalov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu May 13 12:58:11 PDT 2021


dfukalov added a comment.

`getDependency()` call is just a start of processing in GVN, and `MemoryDependenceResults` contains a number of a load' dependencies. One of them was `NonLocal` clobbering dependency between `%tmp4.1 = load i8...` and `%tmp6.1 = load atomic i8...` since latter is atomic (e.g. MemoryDependenceAnalysis.cpp$494-500 <https://reviews.llvm.org/source/llvm-github/browse/main/llvm/lib/Analysis/MemoryDependenceAnalysis.cpp$494-500>). And GVN got this clobbering dependency not from `getDependency()`.

Let's see what happening when GVN processes `%tmp4.1 = load i8, i8* %tmp3.1, align 4` from the following IR

  define void @load_load_partial_alias_atomic(i8* %arg) {
  bb:
    %tmp1.1 = getelementptr inbounds i8, i8* %arg, i64 0
    %tmp2.1 = getelementptr inbounds i8, i8* %arg, i64 1
    %tmp2.2 = bitcast i8* %tmp2.1 to i64*
    %tmp2.3 = load i64, i64* %tmp2.2, align 4
    %tmp2.4 = icmp ugt i64 %tmp2.3, 1
  
    %tmp3.1 = getelementptr inbounds i8, i8* %arg, i64 2
    br label %bb5
  
  bb5:                                              ; preds = %bb14, %bb
    %tmp4.1 = load i8, i8* %tmp3.1, align 4
    %tmp6.1 = load atomic i8, i8* getelementptr inbounds (i8, i8* @global, i64 0) acquire, align 4
    %tmp7.1 = add i8 %tmp6.1, %tmp4.1
    store i8 %tmp7.1, i8* %tmp1.1
    br label %bb5
  
  }

At first, `getDependency()` returns just `NonLocal` dependency and GVN falls to `processNonLocalLoad()` (GVN.cpp$1849-1853) <https://reviews.llvm.org/source/llvm-github/browse/main/llvm/lib/Transforms/Scalar/GVN.cpp$1849-1853>.
Then `getNonLocalPointerDependency()` returns //both// `NonLocal` dependencies (to `%tmp2.3 = load i64...` and to `%tmp6.1 = load atomic i8`).
And then `AnalyzeLoadAvailability()` tries to process them and asks MDA for a clobber offsets, without calling `getDependency()` between their processing.
So GVN thought there are valid clobbering offsets for both of them and tried to optimize incorrect pair of loads (with atomic load one).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95543



More information about the llvm-commits mailing list