[PATCH] D99249: [PassManager] Run additional LICM before LoopRotate
Roman Lebedev via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Mar 31 13:16:49 PDT 2021
lebedev.ri added a comment.
I'm not sure how to write proper interestingness test for this, but e.g. given this input F16057899: reduced.ll <https://reviews.llvm.org/F16057899> (bad example, in the end everything optimizes away)
currently (`-looprotate -licm`):
*** IR Dump After LICMPass ***
; Preheader:
for.end.lr.ph: ; preds = %entry
%hue = getelementptr inbounds %"class.rawspeed::Cr2sRawInterpolator", %"class.rawspeed::Cr2sRawInterpolator"* %this, i64 0, i32 3
%1 = load i32, i32* %hue, align 4, !tbaa !8
%Cb.i.i = getelementptr inbounds %"struct.std::array.30", %"struct.std::array.30"* %MCUs, i64 0, i32 0, i64 undef, i32 0, i64 undef, i32 1
%sub.i.i = add i32 %1, -16384
%Cb.i.i.promoted = load i32, i32* %Cb.i.i, align 4, !tbaa !9
br label %for.end
; Loop:
for.end: ; preds = %for.end.lr.ph, %for.end
%2 = phi i32 [ %Cb.i.i.promoted, %for.end.lr.ph ], [ %add.i.i, %for.end ]
%MCUIdx.03 = phi i32 [ undef, %for.end.lr.ph ], [ %inc21, %for.end ]
%add.i.i = add i32 %sub.i.i, %2
%inc21 = add nsw i32 %MCUIdx.03, 1
%cmp = icmp slt i32 %inc21, %sub
br i1 %cmp, label %for.end, label %for.cond.for.end22_crit_edge, !llvm.loop !11
; Exit blocks
for.cond.for.end22_crit_edge: ; preds = %for.end
%add.i.i.lcssa = phi i32 [ %add.i.i, %for.end ]
store i32 %add.i.i.lcssa, i32* %Cb.i.i, align 4, !tbaa !9
br label %for.end22
with `-licm -loop-rotate`:
*** IR Dump After LoopRotatePass ***
; Preheader:
for.end.lr.ph: ; preds = %entry
br label %for.end
; Loop:
for.end: ; preds = %for.end.lr.ph, %for.end
%MCUIdx.03 = phi i32 [ undef, %for.end.lr.ph ], [ %inc21, %for.end ]
%1 = load i32, i32* %hue, align 4, !tbaa !8
%2 = load i32, i32* %Cb.i.i, align 4, !tbaa !9
%sub.i.i = add i32 %1, -16384
%add.i.i = add i32 %sub.i.i, %2
store i32 %add.i.i, i32* %Cb.i.i, align 4, !tbaa !9
%inc21 = add nsw i32 %MCUIdx.03, 1
%cmp = icmp slt i32 %inc21, %sub
br i1 %cmp, label %for.end, label %for.cond.for.end22_crit_edge, !llvm.loop !11
; Exit blocks
for.cond.for.end22_crit_edge: ; preds = %for.end
br label %for.end22
and with `-licm -loop-rotate -licm`:
*** IR Dump After LICMPass ***
; Preheader:
for.end.lr.ph: ; preds = %entry
%1 = load i32, i32* %hue, align 4, !tbaa !8
%sub.i.i = add i32 %1, -16384
%Cb.i.i.promoted = load i32, i32* %Cb.i.i, align 4, !tbaa !9
br label %for.end
; Loop:
for.end: ; preds = %for.end.lr.ph, %for.end
%2 = phi i32 [ %Cb.i.i.promoted, %for.end.lr.ph ], [ %add.i.i, %for.end ]
%MCUIdx.03 = phi i32 [ undef, %for.end.lr.ph ], [ %inc21, %for.end ]
%add.i.i = add i32 %sub.i.i, %2
%inc21 = add nsw i32 %MCUIdx.03, 1
%cmp = icmp slt i32 %inc21, %sub
br i1 %cmp, label %for.end, label %for.cond.for.end22_crit_edge, !llvm.loop !11
; Exit blocks
for.cond.for.end22_crit_edge: ; preds = %for.end
%add.i.i.lcssa = phi i32 [ %add.i.i, %for.end ]
store i32 %add.i.i.lcssa, i32* %Cb.i.i, align 4, !tbaa !9
br label %for.end22
Note how the `-licm -loop-rotate` causes `%sub.i.i` to be computed in-loop.
Do tell if that isn't sufficient of an answer.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D99249/new/
https://reviews.llvm.org/D99249
More information about the llvm-commits
mailing list