Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions llvm/lib/CodeGen/CodeGenPrepare.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2095,6 +2095,10 @@ static bool isRemOfLoopIncrementWithLoopInvariant(
if (!L->isLoopInvariant(RemAmt))
return false;

// Only works if the AddOffset is a loop invaraint
if (AddOffset && !L->isLoopInvariant(AddOffset))
return false;

// Is the PHI a loop increment?
auto LoopIncrInfo = getIVIncrement(PN, LI);
if (!LoopIncrInfo)
Expand Down
18 changes: 18 additions & 0 deletions llvm/test/Transforms/CodeGenPrepare/X86/fold-loop-of-urem.ll
Original file line number Diff line number Diff line change
Expand Up @@ -1065,3 +1065,21 @@ for.body:
%exitcond.not = icmp eq i32 %inc, %N
br i1 %exitcond.not, label %for.cond.cleanup, label %for.body
}

define i64 @pr150611_add_offset_is_not_loop_invariant(i1 %cond) {
entry:
%remamt = select i1 %cond, i64 2, i64 0
br label %for.body

for.body:
%indvars = phi i64 [ 0, %entry ], [ %indvars.next, %for.body ]
%add.offset = zext i1 %cond to i64
%add = add nuw i64 %indvars, %add.offset
%rem = urem i64 %add, %remamt
%indvars.next = add nuw i64 %indvars, 1
%exitcond = icmp eq i64 %indvars.next, 3
br i1 %exitcond, label %for.exit, label %for.body

for.exit:
ret i64 %rem
}
Loading