-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[InstCombine] Canonicalise SextADD + GEP #69581
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
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,74 @@ | ||
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 3 | ||
; RUN: opt < %s -passes=instcombine -S | FileCheck %s | ||
|
||
define void @test(ptr %ptr, i32 %a, i32 %b) { | ||
; CHECK-LABEL: define void @test( | ||
; CHECK-SAME: ptr [[PTR:%.*]], i32 [[A:%.*]], i32 [[B:%.*]]) { | ||
; CHECK-NEXT: entry: | ||
; CHECK-NEXT: [[TMP0:%.*]] = sext i32 [[A]] to i64 | ||
; CHECK-NEXT: [[TMP1:%.*]] = getelementptr i32, ptr [[PTR]], i64 [[TMP0]] | ||
; CHECK-NEXT: [[GEP:%.*]] = getelementptr i32, ptr [[TMP1]], i64 10 | ||
; CHECK-NEXT: store i32 [[B]], ptr [[GEP]], align 4 | ||
; CHECK-NEXT: ret void | ||
; | ||
entry: | ||
%add = add nsw i32 %a, 10 | ||
%idx = sext i32 %add to i64 | ||
%gep = getelementptr inbounds i32, ptr %ptr, i64 %idx | ||
store i32 %b, ptr %gep | ||
ret void | ||
} | ||
|
||
define i32 @test_add_res_moreoneuse(ptr %ptr, i32 %a, i32 %b) { | ||
; CHECK-LABEL: define i32 @test_add_res_moreoneuse( | ||
; CHECK-SAME: ptr [[PTR:%.*]], i32 [[A:%.*]], i32 [[B:%.*]]) { | ||
; CHECK-NEXT: entry: | ||
; CHECK-NEXT: [[ADD:%.*]] = add nsw i32 [[A]], 5 | ||
; CHECK-NEXT: [[IDX:%.*]] = sext i32 [[ADD]] to i64 | ||
; CHECK-NEXT: [[GEP:%.*]] = getelementptr inbounds i32, ptr [[PTR]], i64 [[IDX]] | ||
; CHECK-NEXT: store i32 [[B]], ptr [[GEP]], align 4 | ||
; CHECK-NEXT: ret i32 [[ADD]] | ||
; | ||
entry: | ||
%add = add nsw i32 %a, 5 | ||
%idx = sext i32 %add to i64 | ||
%gep = getelementptr inbounds i32, ptr %ptr, i64 %idx | ||
store i32 %b, ptr %gep | ||
ret i32 %add | ||
} | ||
|
||
define void @test_addop_nonsw_flag(ptr %ptr, i32 %a, i32 %b) { | ||
; CHECK-LABEL: define void @test_addop_nonsw_flag( | ||
; CHECK-SAME: ptr [[PTR:%.*]], i32 [[A:%.*]], i32 [[B:%.*]]) { | ||
; CHECK-NEXT: entry: | ||
; CHECK-NEXT: [[ADD:%.*]] = add i32 [[A]], 10 | ||
; CHECK-NEXT: [[IDX:%.*]] = sext i32 [[ADD]] to i64 | ||
; CHECK-NEXT: [[GEP:%.*]] = getelementptr inbounds i32, ptr [[PTR]], i64 [[IDX]] | ||
; CHECK-NEXT: store i32 [[B]], ptr [[GEP]], align 4 | ||
; CHECK-NEXT: ret void | ||
; | ||
entry: | ||
%add = add i32 %a, 10 | ||
%idx = sext i32 %add to i64 | ||
%gep = getelementptr inbounds i32, ptr %ptr, i64 %idx | ||
store i32 %b, ptr %gep | ||
ret void | ||
} | ||
|
||
define void @test_add_op2_not_constant(ptr %ptr, i32 %a, i32 %b) { | ||
; CHECK-LABEL: define void @test_add_op2_not_constant( | ||
; CHECK-SAME: ptr [[PTR:%.*]], i32 [[A:%.*]], i32 [[B:%.*]]) { | ||
; CHECK-NEXT: entry: | ||
; CHECK-NEXT: [[ADD:%.*]] = add i32 [[A]], [[B]] | ||
; CHECK-NEXT: [[IDX:%.*]] = sext i32 [[ADD]] to i64 | ||
; CHECK-NEXT: [[GEP:%.*]] = getelementptr inbounds i32, ptr [[PTR]], i64 [[IDX]] | ||
; CHECK-NEXT: store i32 [[B]], ptr [[GEP]], align 4 | ||
; CHECK-NEXT: ret void | ||
; | ||
entry: | ||
%add = add i32 %a, %b | ||
%idx = sext i32 %add to i64 | ||
%gep = getelementptr inbounds i32, ptr %ptr, i64 %idx | ||
store i32 %b, ptr %gep | ||
ret void | ||
} | ||
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.