mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-11-02 07:17:36 +00:00
InstCombine: Make OptimizePointerDifference more aggressive.
- Ignore pointer casts. - Also expand GEPs that aren't constantexprs when they have one use or only constant indices. - We now compile "&foo[i] - &foo[j]" into "i - j". git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@150961 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -301,3 +301,29 @@ define i32 @test28(i32 %x, i32 %y, i32 %z) {
|
||||
; CHECK-NEXT: add i32
|
||||
; CHECK-NEXT: ret i32
|
||||
}
|
||||
|
||||
define i64 @test29(i8* %foo, i64 %i, i64 %j) {
|
||||
%gep1 = getelementptr inbounds i8* %foo, i64 %i
|
||||
%gep2 = getelementptr inbounds i8* %foo, i64 %j
|
||||
%cast1 = ptrtoint i8* %gep1 to i64
|
||||
%cast2 = ptrtoint i8* %gep2 to i64
|
||||
%sub = sub i64 %cast1, %cast2
|
||||
ret i64 %sub
|
||||
; CHECK: @test29
|
||||
; CHECK-NEXT: sub i64 %i, %j
|
||||
; CHECK-NEXT: ret i64
|
||||
}
|
||||
|
||||
define i64 @test30(i8* %foo, i64 %i, i64 %j) {
|
||||
%bit = bitcast i8* %foo to i32*
|
||||
%gep1 = getelementptr inbounds i32* %bit, i64 %i
|
||||
%gep2 = getelementptr inbounds i8* %foo, i64 %j
|
||||
%cast1 = ptrtoint i32* %gep1 to i64
|
||||
%cast2 = ptrtoint i8* %gep2 to i64
|
||||
%sub = sub i64 %cast1, %cast2
|
||||
ret i64 %sub
|
||||
; CHECK: @test30
|
||||
; CHECK-NEXT: %gep1.idx = shl nuw i64 %i, 2
|
||||
; CHECK-NEXT: sub i64 %gep1.idx, %j
|
||||
; CHECK-NEXT: ret i64
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user