[PATCH] D118143: [GVN] Support loop load PRE through pointer select.

Florian Hahn via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 28 08:03:14 PST 2022


fhahn updated this revision to Diff 404028.
fhahn added a comment.

In D118143#3277366 <https://reviews.llvm.org/D118143#3277366>, @reames wrote:

> @fhahn This really looks like an extension of full redundancy elimination.  If we had the select expressed as a phi/branch pattern, wouldn't we be able to determine the value is fully available and do SSA construction to propagate the loaded value?  If so, then this feels like a case where we should extend the fully available logic and SSA construction in FRE rather than add a parallel transform.
>
> (p.s. I might be missing something obvious.  Writing this in a hurry to get you any response at all due to personal life craziness atm.)

Thanks! It seems like this indeed fits rather nicely into the available-value logic.  I updated the patch to introduce a new SelectVal to AvailableValueInBlock and create those nodes as needed, together with the required materialization code.

This version does not replace the load outside the loop of the pointer-select for now. But that might be also be do-able separately by teaching the available value analysis to replace the load %res with the select %0 in the code below.

  define i32 @src(i32* %ptr, i32* %end) {
  entry:
    %start.ptr = getelementptr inbounds i32, i32* %ptr, i64 1
    %l.2.pre = load i32, i32* %ptr, align 4
    br label %loop
  
  loop:                                             ; preds = %loop, %entry
    %l.2 = phi i32 [ %l.2.pre, %entry ], [ %0, %loop ]
    %ptr.iv = phi i32* [ %start.ptr, %entry ], [ %ptr.iv.next, %loop ]
    %min.ptr = phi i32* [ %ptr, %entry ], [ %min.select, %loop ]
    %l.1 = load i32, i32* %ptr.iv, align 4
    %cmp.i.i.i = icmp ult i32 %l.1, %l.2
    %0 = select i1 %cmp.i.i.i, i32 %l.1, i32 %l.2
    %min.select = select i1 %cmp.i.i.i, i32* %ptr.iv, i32* %min.ptr
    %ptr.iv.next = getelementptr inbounds i32, i32* %ptr.iv, i64 1
    %ec = icmp eq i32* %ptr.iv.next, %end
    br i1 %ec, label %exit, label %loop
  
  exit:                                             ; preds = %loop
    %res = load i32, i32* %min.select, align 4
    ret i32 %res
  }


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118143

Files:
  llvm/lib/Transforms/Scalar/GVN.cpp
  llvm/test/Transforms/GVN/PRE/pre-loop-load-through-select.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D118143.404028.patch
Type: text/x-patch
Size: 22483 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220128/2251a29e/attachment.bin>


More information about the llvm-commits mailing list