-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Bail out jump threading on indirect branches #103688
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
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 104 additions & 0 deletions
104
llvm/test/Transforms/SimplifyCFG/switch-branch-fold-indirectbr-102351.ll
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5 | ||
; RUN: opt < %s -passes=simplifycfg -S | FileCheck %s | ||
|
||
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" | ||
hiraditya marked this conversation as resolved.
Show resolved
Hide resolved
|
||
target triple = "x86_64-unknown-linux-gnu" | ||
|
||
define dso_local noundef i32 @main() { | ||
; CHECK-LABEL: define dso_local noundef i32 @main() { | ||
; CHECK-NEXT: [[BB:.*]]: | ||
; CHECK-NEXT: [[ALLOCA:%.*]] = alloca [2 x ptr], align 16 | ||
; CHECK-NEXT: store ptr blockaddress(@main, %[[BB4:.*]]), ptr [[ALLOCA]], align 16, !tbaa [[TBAA0:![0-9]+]] | ||
; CHECK-NEXT: [[GETELEMENTPTR:%.*]] = getelementptr inbounds [2 x ptr], ptr [[ALLOCA]], i64 0, i64 1 | ||
; CHECK-NEXT: store ptr blockaddress(@main, %[[BB10:.*]]), ptr [[GETELEMENTPTR]], align 8, !tbaa [[TBAA0]] | ||
; CHECK-NEXT: br label %[[BB1:.*]] | ||
; CHECK: [[BB1]]: | ||
; CHECK-NEXT: [[PHI:%.*]] = phi i32 [ 0, %[[BB]] ], [ [[PHI8:%.*]], %[[BB7:.*]] ] | ||
; CHECK-NEXT: [[PHI2:%.*]] = phi i32 [ 0, %[[BB]] ], [ [[PHI9:%.*]], %[[BB7]] ] | ||
; CHECK-NEXT: switch i32 [[PHI]], label %[[BB7]] [ | ||
; CHECK-NEXT: i32 0, label %[[BB12:.*]] | ||
; CHECK-NEXT: i32 1, label %[[BB4]] | ||
; CHECK-NEXT: i32 2, label %[[BB6:.*]] | ||
; CHECK-NEXT: ] | ||
; CHECK: [[BB4]]: | ||
; CHECK-NEXT: [[PHI5:%.*]] = phi i32 [ [[PHI13:%.*]], %[[BB12]] ], [ [[PHI2]], %[[BB1]] ] | ||
; CHECK-NEXT: br label %[[BB7]] | ||
; CHECK: [[BB6]]: | ||
; CHECK-NEXT: [[CALL:%.*]] = call i32 @foo(i32 noundef [[PHI2]]) | ||
; CHECK-NEXT: [[ADD:%.*]] = add nsw i32 [[PHI2]], 1 | ||
; CHECK-NEXT: br label %[[BB12]] | ||
; CHECK: [[BB7]]: | ||
; CHECK-NEXT: [[PHI8]] = phi i32 [ [[PHI]], %[[BB1]] ], [ 2, %[[BB4]] ] | ||
; CHECK-NEXT: [[PHI9]] = phi i32 [ [[PHI2]], %[[BB1]] ], [ [[PHI5]], %[[BB4]] ] | ||
; CHECK-NEXT: br label %[[BB1]], !llvm.loop [[LOOP4:![0-9]+]] | ||
; CHECK: [[BB10]]: | ||
; CHECK-NEXT: [[CALL11:%.*]] = call i32 @foo(i32 noundef [[PHI13]]) | ||
; CHECK-NEXT: ret i32 0 | ||
; CHECK: [[BB12]]: | ||
; CHECK-NEXT: [[PHI13]] = phi i32 [ [[ADD]], %[[BB6]] ], [ [[PHI2]], %[[BB1]] ] | ||
; CHECK-NEXT: [[SEXT:%.*]] = sext i32 [[PHI13]] to i64 | ||
; CHECK-NEXT: [[GETELEMENTPTR14:%.*]] = getelementptr inbounds [2 x ptr], ptr [[ALLOCA]], i64 0, i64 [[SEXT]] | ||
; CHECK-NEXT: [[LOAD:%.*]] = load ptr, ptr [[GETELEMENTPTR14]], align 8, !tbaa [[TBAA0]] | ||
; CHECK-NEXT: indirectbr ptr [[LOAD]], [label %[[BB4]], label %bb10] | ||
; | ||
bb: | ||
%alloca = alloca [2 x ptr], align 16 | ||
store ptr blockaddress(@main, %bb4), ptr %alloca, align 16, !tbaa !0 | ||
%getelementptr = getelementptr inbounds [2 x ptr], ptr %alloca, i64 0, i64 1 | ||
store ptr blockaddress(@main, %bb10), ptr %getelementptr, align 8, !tbaa !0 | ||
br label %bb1 | ||
|
||
bb1: ; preds = %bb7, %bb | ||
%phi = phi i32 [ 0, %bb ], [ %phi8, %bb7 ] | ||
%phi2 = phi i32 [ 0, %bb ], [ %phi9, %bb7 ] | ||
switch i32 %phi, label %bb7 [ | ||
i32 0, label %bb3 | ||
i32 1, label %bb4 | ||
i32 2, label %bb6 | ||
] | ||
|
||
bb3: ; preds = %bb1 | ||
br label %bb12 | ||
|
||
bb4: ; preds = %bb12, %bb1 | ||
%phi5 = phi i32 [ %phi13, %bb12 ], [ %phi2, %bb1 ] | ||
br label %bb7 | ||
|
||
bb6: ; preds = %bb1 | ||
%call = call i32 @foo(i32 noundef %phi2) | ||
%add = add nsw i32 %phi2, 1 | ||
br label %bb12 | ||
|
||
bb7: ; preds = %bb4, %bb1 | ||
%phi8 = phi i32 [ %phi, %bb1 ], [ 2, %bb4 ] | ||
%phi9 = phi i32 [ %phi2, %bb1 ], [ %phi5, %bb4 ] | ||
br label %bb1, !llvm.loop !4 | ||
|
||
bb10: ; preds = %bb12 | ||
%call11 = call i32 @foo(i32 noundef %phi13) | ||
ret i32 0 | ||
|
||
bb12: ; preds = %bb6, %bb3 | ||
%phi13 = phi i32 [ %add, %bb6 ], [ %phi2, %bb3 ] | ||
%sext = sext i32 %phi13 to i64 | ||
%getelementptr14 = getelementptr inbounds [2 x ptr], ptr %alloca, i64 0, i64 %sext | ||
%load = load ptr, ptr %getelementptr14, align 8, !tbaa !0 | ||
indirectbr ptr %load, [label %bb4, label %bb10] | ||
} | ||
|
||
declare i32 @foo(i32) | ||
|
||
!0 = !{!1, !1, i64 0} | ||
!1 = !{!"any pointer", !2, i64 0} | ||
!2 = !{!"omnipotent char", !3, i64 0} | ||
!3 = !{!"Simple C++ TBAA"} | ||
!4 = !{!5, !5, i64 0} | ||
!5 = !{!"int", !2, i64 0} | ||
;. | ||
; CHECK: [[TBAA0]] = !{[[META1:![0-9]+]], [[META1]], i64 0} | ||
; CHECK: [[META1]] = !{!"any pointer", [[META2:![0-9]+]], i64 0} | ||
; CHECK: [[META2]] = !{!"omnipotent char", [[META3:![0-9]+]], i64 0} | ||
; CHECK: [[META3]] = !{!"Simple C++ TBAA"} | ||
; CHECK: [[LOOP4]] = !{[[META5:![0-9]+]], [[META5]], i64 0} | ||
; CHECK: [[META5]] = !{!"int", [[META2]], i64 0} | ||
;. |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.