Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[InstSimplify] Remove zero-index opaque pointer GEP
With opaque pointers, a zero-index GEP is a no-op. It does not need to be retained for the pointer element type change it may perform.
- Loading branch information
Showing
2 changed files
with
34 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py | ||
; RUN: opt -S -instsimplify -opaque-pointers < %s | FileCheck %s | ||
|
||
define ptr @gep_zero_indices(ptr %p) { | ||
; CHECK-LABEL: @gep_zero_indices( | ||
; CHECK-NEXT: ret ptr [[P:%.*]] | ||
; | ||
%p2 = getelementptr { i64, i64 }, ptr %p, i64 0, i32 0 | ||
ret ptr %p2 | ||
} | ||
|
||
define ptr @gep_non_zero_indices1(ptr %p) { | ||
; CHECK-LABEL: @gep_non_zero_indices1( | ||
; CHECK-NEXT: [[P2:%.*]] = getelementptr { i64, i64 }, ptr [[P:%.*]], i64 0, i32 1 | ||
; CHECK-NEXT: ret ptr [[P2]] | ||
; | ||
%p2 = getelementptr { i64, i64 }, ptr %p, i64 0, i32 1 | ||
ret ptr %p2 | ||
} | ||
|
||
define ptr @gep_non_zero_indices2(ptr %p) { | ||
; CHECK-LABEL: @gep_non_zero_indices2( | ||
; CHECK-NEXT: [[P2:%.*]] = getelementptr { i64, i64 }, ptr [[P:%.*]], i64 1, i32 0 | ||
; CHECK-NEXT: ret ptr [[P2]] | ||
; | ||
%p2 = getelementptr { i64, i64 }, ptr %p, i64 1, i32 0 | ||
ret ptr %p2 | ||
} |