Skip to content

[llvm][LSR] Fix where invariant on ScaledReg & Scale is violated #112576

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 6 additions & 2 deletions llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,9 @@ static bool containsAddRecDependentOnLoop(const SCEV *S, const Loop &L) {
/// representation.
/// \see Formula::BaseRegs.
bool Formula::isCanonical(const Loop &L) const {
assert((Scale == 0 || ScaledReg) &&
"ScaledReg must be non-null if Scale is non-zero");

if (!ScaledReg)
return BaseRegs.size() <= 1;

Expand Down Expand Up @@ -3973,9 +3976,10 @@ void LSRInstance::GenerateReassociationsImpl(LSRUse &LU, unsigned LUIdx,
F.UnfoldedOffset =
Immediate::getFixed((uint64_t)F.UnfoldedOffset.getFixedValue() +
InnerSumSC->getValue()->getZExtValue());
if (IsScaledReg)
if (IsScaledReg) {
F.ScaledReg = nullptr;
else
F.Scale = 0;
} else
F.BaseRegs.erase(F.BaseRegs.begin() + Idx);
} else if (IsScaledReg)
F.ScaledReg = InnerSum;
Expand Down
30 changes: 30 additions & 0 deletions llvm/test/Transforms/LoopStrengthReduce/X86/pr76504.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
; Reduced from https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=65323 by @RKSimon
;
; RUN: opt -S -passes=loop-reduce %s | FileCheck %s
;
; Make sure we don't trigger an assertion.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the future please use filename that are more expressive.
You can still reference the bug number in the comment.


target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

@G = external global i32

define void @foo() {
; CHECK-LABEL: foo
bb8:
br label %bb30

bb30: ; preds = %bb30, %bb8
%l0 = phi i64 [ -2222, %bb8 ], [ %r23, %bb30 ]
%A22 = alloca i16, align 2
%r23 = add nuw i64 1, %l0
%G7 = getelementptr i16, ptr %A22, i64 %r23
%B15 = urem i64 %r23, %r23
%G6 = getelementptr i16, ptr %G7, i64 %B15
%B1 = urem i64 %r23, %r23
%B8 = sub i64 -1, %r23
%B18 = sub i64 %B8, %B1
%G5 = getelementptr i16, ptr %G6, i64 %B18
store ptr %G5, ptr undef, align 8
br label %bb30
}
Loading