-
Notifications
You must be signed in to change notification settings - Fork 12.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ArgPromotion][Attributor] Update min-legal-vector-width when do prom…
…otion X86 codegen uses function attribute `min-legal-vector-width` to select the proper ABI. The intention of the attribute is to reflect user's requirement when they passing or returning vector arguments. So Clang front-end will iterate the vector arguments and set `min-legal-vector-width` to the width of the maximum for both caller and callee. It is assumed any middle end optimizations won't care of the attribute expect inlining and argument promotion. - For inlining, we will propagate the attribute of inlined functions because the inlining functions become the newer caller. - For argument promotion, we check the `min-legal-vector-width` of the caller and callee and refuse to promote when they don't match. The problem comes from the optimizations' combination, as shown by https://godbolt.org/z/zo3hba8xW. The caller `foo` has two callees `bar` and `baz`. When doing argument promotion, both `foo` and `bar` has the same `min-legal-vector-width`. So the argument was promoted to vector. Then the inlining inlines `baz` to `foo` and updates `min-legal-vector-width`, which results in ABI mismatch between `foo` and `bar`. This patch fixes the problem by expanding the concept of `min-legal-vector-width` to indicator of functions arguments. That says, any passes touch functions arguments have to set `min-legal-vector-width` to the value reflects the width of vector arguments. It makes sense to me because any arguments modifications are ABI related and should response for the ABI compatibility. Differential Revision: https://reviews.llvm.org/D123284
- Loading branch information
1 parent
e6295c6
commit 7c04454
Showing
7 changed files
with
134 additions
and
51 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
25 changes: 25 additions & 0 deletions
25
llvm/test/Transforms/ArgumentPromotion/min-legal-vector-width.ll
This file contains 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,25 @@ | ||
; RUN: opt < %s -passes=argpromotion -S | FileCheck %s | ||
|
||
; CHECK-LABEL: define i32 @foo() #0 { | ||
; CHECK-NEXT: %.val = load <32 x half>, <32 x half>* undef, align 4 | ||
; CHECK-NEXT: call void @bar(<32 x half> %.val) | ||
; CHECK-NEXT: ret i32 0 | ||
; CHECK-NEXT: } | ||
|
||
; CHECK-LABEL: define internal void @bar(<32 x half> %.0.val) #0 { | ||
; CHECK-NEXT: ret void | ||
; CHECK-NEXT: } | ||
|
||
; CHECK: attributes #0 = { uwtable "min-legal-vector-width"="512" } | ||
|
||
define i32 @foo() #0 { | ||
call void @bar(<32 x half>* undef) | ||
ret i32 0 | ||
} | ||
|
||
define internal void @bar(<32 x half>*) #0 { | ||
%2 = load <32 x half>, <32 x half>* %0, align 4 | ||
ret void | ||
} | ||
|
||
attributes #0 = { uwtable "min-legal-vector-width"="0" } |
Oops, something went wrong.