[llvm-dev] Question about hoisting LoadInst in LICM pass using MemorySSA/AliasAnalysis
Jingu Kang via llvm-dev
llvm-dev at lists.llvm.org
Fri Oct 29 11:26:48 PDT 2021
Ping
From: llvm-dev <llvm-dev-bounces at lists.llvm.org> On Behalf Of Jingu Kang via llvm-dev
Sent: 27 October 2021 15:15
To: llvm-dev at lists.llvm.org
Subject: [llvm-dev] Question about hoisting LoadInst in LICM pass using MemorySSA/AliasAnalysis
Hi All,
I have a question about hoisting LoadInst in LICM pass. I am looking at below IR code.
@a = dso_local local_unnamed_addr global i32** null, align 8
define dso_local void @foo(i32 %max) {
entry:
br label %for.cond
for.cond: ; preds = %for.body, %entry
%i.0 = phi i32 [ 0, %entry ], [ %inc, %for.body ]
%cmp.not = icmp sgt i32 %i.0, %max
br i1 %cmp.not, label %for.cond.cleanup, label %for.body
for.cond.cleanup: ; preds = %for.cond
ret void
for.body: ; preds = %for.cond
%0 = load i32**, i32*** @a, align 8, !tbaa !8
%idxprom = zext i32 %i.0 to i64
%arrayidx = getelementptr inbounds i32*, i32** %0, i64 %idxprom
store i32* null, i32** %arrayidx, align 8, !tbaa !8
%inc = add nuw nsw i32 %i.0, 1
br label %for.cond, !llvm.loop !12
}
I have expected the `%0 = load` is hoisted to entry block because I think it is loop invariant. However, LICM pass fails to hoist it because the MemorySSA is as below.
define dso_local void @foo(i32 %max) local_unnamed_addr #0 {
entry:
br label %for.cond
for.cond: ; preds = %for.body, %entry
; 2 = MemoryPhi({entry,liveOnEntry},{for.body,1})
%i.0 = phi i32 [ 0, %entry ], [ %inc, %for.body ]
%cmp.not = icmp sgt i32 %i.0, %max
br i1 %cmp.not, label %for.cond.cleanup, label %for.body
for.cond.cleanup: ; preds = %for.cond
ret void
for.body: ; preds = %for.cond
; MemoryUse(2) MayAlias
%0 = load i32**, i32*** @a, align 8, !tbaa !8
%idxprom = zext i32 %i.0 to i64
%arrayidx = getelementptr inbounds i32*, i32** %0, i64 %idxprom
; 1 = MemoryDef(2)
store i32* null, i32** %arrayidx, align 8, !tbaa !8
%inc = add nuw nsw i32 %i.0, 1
br label %for.cond, !llvm.loop !12
}
As we can see there is `MemoryUse(2) MayAlias` above the `%0 = load` because AliasAnalysis returns MayAlias between the ‘%0 = load’ and ‘store i32* null’. I think it could be `MemoryUse(liveOnEntry)`. How do you think about it? If I missed something, please let me know.
Thanks,
JinGu Kang
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20211029/5258492b/attachment.html>
More information about the llvm-dev
mailing list