- Notifications
You must be signed in to change notification settings - Fork 15k
[DA] Fix crash when two loops have different type sizes of becount #165021
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
base: main
Are you sure you want to change the base?
Conversation
| @llvm/pr-subscribers-llvm-analysis Author: Shimin Cui (scui-ibm) ChangesThe type sizes of backedge taken counts for two loops can be different and this is to fix the crash in haveSameSD (#165014). Full diff: https://github.com/llvm/llvm-project/pull/165021.diff 2 Files Affected:
diff --git a/llvm/lib/Analysis/DependenceAnalysis.cpp b/llvm/lib/Analysis/DependenceAnalysis.cpp index a572eefddd20e..3e9b9ee77640f 100644 --- a/llvm/lib/Analysis/DependenceAnalysis.cpp +++ b/llvm/lib/Analysis/DependenceAnalysis.cpp @@ -1131,9 +1131,18 @@ bool DependenceInfo::haveSameSD(const Loop *SrcLoop, if (SE->hasLoopInvariantBackedgeTakenCount(DstLoop)) DstUP = SE->getBackedgeTakenCount(DstLoop); - if (SrcUB != nullptr && DstUP != nullptr && - SE->isKnownPredicate(ICmpInst::ICMP_EQ, SrcUB, DstUP)) - return true; + if (SrcUB != nullptr && DstUP != nullptr) { + unsigned SrcBitWidth = SE->getTypeSizeInBits(SrcUB->getType()); + unsigned DstBitWidth = SE->getTypeSizeInBits(DstUP->getType()); + if (SrcBitWidth < DstBitWidth) { + SrcUB = SE->getZeroExtendExpr(SrcUB, DstUP->getType()); + } else if (SrcBitWidth > DstBitWidth) { + DstUP = SE->getZeroExtendExpr(DstUP, SrcUB->getType()); + } + + if (SE->isKnownPredicate(ICmpInst::ICMP_EQ, SrcUB, DstUP)) + return true; + } return false; } diff --git a/llvm/test/Analysis/DependenceAnalysis/same-sd-for-diff-becount-type-loops.ll b/llvm/test/Analysis/DependenceAnalysis/same-sd-for-diff-becount-type-loops.ll new file mode 100644 index 0000000000000..66880b5a553ec --- /dev/null +++ b/llvm/test/Analysis/DependenceAnalysis/same-sd-for-diff-becount-type-loops.ll @@ -0,0 +1,68 @@ +; RUN: opt < %s -disable-output "-passes=print<da>" -aa-pipeline=basic-aa 2>&1 | FileCheck %s + +define void @f1() { +; CHECK-LABEL: 'f1' +; CHECK-NEXT: Src: store i32 0, ptr null, align 4 --> Dst: store i32 0, ptr null, align 4 +; CHECK-NEXT: da analyze - consistent output [S]! +; CHECK-NEXT: Src: store i32 0, ptr null, align 4 --> Dst: %2 = load i32, ptr null, align 4 +; CHECK-NEXT: da analyze - consistent flow [|<]! +; CHECK-NEXT: Src: %2 = load i32, ptr null, align 4 --> Dst: %2 = load i32, ptr null, align 4 +; CHECK-NEXT: da analyze - consistent input [S]! +; +entry: + br label %for.1.header + +for.1.header: ; preds = %for.2.end, %entry + br label %for.1.body + +for.1.body: ; preds = %for.1.body, %whiledo + %0 = phi i32 [ 0, %for.1.header ], [ 1, %for.1.body ] + store i32 0, ptr null, align 4 + %1 = icmp ult i32 %0, 1 + br i1 %1, label %for.1.body, label %for.1.end + +for.1.end: ; preds = %for.1.body + br label %for.2.body + +for.2.body: ; preds = %for.2.body, %for.1.end + %2 = load i32, ptr null, align 4 + br i1 false, label %for.2.body, label %exit + +exit: ; preds = %for.2.body + ret void +} + +define void @f2() { +; CHECK-LABEL: 'f2' +; CHECK-NEXT: Src: store i32 0, ptr null, align 4 --> Dst: store i32 0, ptr null, align 4 +; CHECK-NEXT: da analyze - consistent output [S]! +; CHECK-NEXT: Src: store i32 0, ptr null, align 4 --> Dst: %3 = load i32, ptr null, align 4 +; CHECK-NEXT: da analyze - flow [|<] / assuming 1 loop level(s) fused: [S|<]! +; CHECK-NEXT: Src: %3 = load i32, ptr null, align 4 --> Dst: %3 = load i32, ptr null, align 4 +; CHECK-NEXT: da analyze - consistent input [S]! +; +entry: + br label %for.1.header + +for.1.header: ; preds = %for.2.end, %entry + br label %for.1.body + +for.1.body: ; preds = %for.1.body, %whiledo + %0 = phi i32 [ 0, %for.1.header ], [ 1, %for.1.body ] + store i32 0, ptr null, align 4 + %1 = icmp ult i32 %0, 1 + br i1 %1, label %for.1.body, label %for.1.end + +for.1.end: ; preds = %for.1.body + br label %for.2.body + +for.2.body: ; preds = %for.2.body, %for.1.end + %2 = phi i64 [ 0, %for.1.end ], [ %4, %for.2.body ] + %3 = load i32, ptr null, align 4 + %4 = add nuw nsw i64 %2, 1 + %5 = icmp ult i64 %4, 2 + br i1 %5, label %for.2.body, label %exit + +exit: ; preds = %for.2.body + ret void +} |
| SE->isKnownPredicate(ICmpInst::ICMP_EQ, SrcUB, DstUP)) | ||
| return true; | ||
| if (SrcUB != nullptr && DstUP != nullptr) { | ||
| unsigned SrcBitWidth = SE->getTypeSizeInBits(SrcUB->getType()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could use SE.getWiderType/getNoopOrZeroExtend
The type sizes of backedge taken counts for two loops can be different and this is to fix the crash in haveSameSD (#165014).