summaryrefslogtreecommitdiffstats
path: root/llvm/test
diff options
context:
space:
mode:
authorBenjamin Kramer <benny.kra@googlemail.com>2012-02-20 14:34:57 +0000
committerBenjamin Kramer <benny.kra@googlemail.com>2012-02-20 14:34:57 +0000
commit7746eb62fb77d3c8ca5678d3261cb198c8cd5124 (patch)
tree0ae0e18ad9795dcf42ad6f6d65edc37cac6f6d93 /llvm/test
parent232c4f50ba576e9a23918756dff302b651288d66 (diff)
downloadbcm5719-llvm-7746eb62fb77d3c8ca5678d3261cb198c8cd5124.tar.gz
bcm5719-llvm-7746eb62fb77d3c8ca5678d3261cb198c8cd5124.zip
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". llvm-svn: 150961
Diffstat (limited to 'llvm/test')
-rw-r--r--llvm/test/Transforms/InstCombine/sub.ll26
1 files changed, 26 insertions, 0 deletions
diff --git a/llvm/test/Transforms/InstCombine/sub.ll b/llvm/test/Transforms/InstCombine/sub.ll
index 37de3281358..b71ec8c98f8 100644
--- a/llvm/test/Transforms/InstCombine/sub.ll
+++ b/llvm/test/Transforms/InstCombine/sub.ll
@@ -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
+}
OpenPOWER on IntegriCloud