-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[InlineCost] Simplify extractvalue across callsite #145054
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test also passes without your change. You could use a recursive call to prove that the recursive code path is eliminated. Alternative could check debug output. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oops, x86 has lower cost than AArch64 here. Thanks! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you please also add a negative test where extractvalue does not simplify (e.g. same as current but swap 0 and 1). |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5 | ||
; RUN: opt < %s -S -passes=inline | FileCheck %s | ||
|
||
define i32 @callee([2 x i32] %agg) { | ||
; CHECK-LABEL: define i32 @callee( | ||
; CHECK-SAME: [2 x i32] [[AGG:%.*]]) { | ||
; CHECK-NEXT: [[V:%.*]] = extractvalue [2 x i32] [[AGG]], 0 | ||
; CHECK-NEXT: [[C:%.*]] = icmp eq i32 [[V]], 0 | ||
; CHECK-NEXT: br i1 [[C]], label %[[IS_NULL:.*]], label %[[NON_NULL:.*]] | ||
; CHECK: [[IS_NULL]]: | ||
; CHECK-NEXT: ret i32 0 | ||
; CHECK: [[NON_NULL]]: | ||
; CHECK-NEXT: [[R:%.*]] = call i32 @callee([2 x i32] [[AGG]]) | ||
; CHECK-NEXT: ret i32 [[R]] | ||
; | ||
%v = extractvalue [2 x i32] %agg, 0 | ||
%c = icmp eq i32 %v, 0 | ||
br i1 %c, label %is_null, label %non_null | ||
|
||
is_null: | ||
ret i32 0 | ||
|
||
non_null: | ||
%r = call i32 @callee([2 x i32] %agg) | ||
ret i32 %r | ||
} | ||
|
||
define i32 @caller_simplified(i32 %arg) { | ||
; CHECK-LABEL: define i32 @caller_simplified( | ||
; CHECK-SAME: i32 [[ARG:%.*]]) { | ||
; CHECK-NEXT: [[AGG0:%.*]] = insertvalue [2 x i32] poison, i32 0, 0 | ||
; CHECK-NEXT: [[AGG1:%.*]] = insertvalue [2 x i32] [[AGG0]], i32 [[ARG]], 1 | ||
; CHECK-NEXT: ret i32 0 | ||
; | ||
%agg0 = insertvalue [2 x i32] poison, i32 0, 0 | ||
%agg1 = insertvalue [2 x i32] %agg0, i32 %arg, 1 | ||
%v = call i32 @callee([2 x i32] %agg1) | ||
ret i32 %v | ||
} | ||
|
||
define i32 @caller_not_simplified(i32 %arg) { | ||
; CHECK-LABEL: define i32 @caller_not_simplified( | ||
; CHECK-SAME: i32 [[ARG:%.*]]) { | ||
; CHECK-NEXT: [[AGG0:%.*]] = insertvalue [2 x i32] poison, i32 1, 0 | ||
; CHECK-NEXT: [[AGG1:%.*]] = insertvalue [2 x i32] [[AGG0]], i32 [[ARG]], 1 | ||
; CHECK-NEXT: [[V:%.*]] = call i32 @callee([2 x i32] [[AGG1]]) | ||
; CHECK-NEXT: ret i32 [[V]] | ||
; | ||
%agg0 = insertvalue [2 x i32] poison, i32 1, 0 | ||
%agg1 = insertvalue [2 x i32] %agg0, i32 %arg, 1 | ||
%v = call i32 @callee([2 x i32] %agg1) | ||
ret i32 %v | ||
} |
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.
It would be good to split off the change from constant -> constant and then improve extract value handling in a separate pqtch