[llvm] 7020781 - [InstCombine] add ptr difference tests; NFC
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 7 12:54:50 PDT 2020
Author: Sanjay Patel
Date: 2020-09-07T15:54:32-04:00
New Revision: 70207816e35771459d053ab9faf75a50a4cb92fb
URL: https://github.com/llvm/llvm-project/commit/70207816e35771459d053ab9faf75a50a4cb92fb
DIFF: https://github.com/llvm/llvm-project/commit/70207816e35771459d053ab9faf75a50a4cb92fb.diff
LOG: [InstCombine] add ptr difference tests; NFC
Added:
Modified:
llvm/test/Transforms/InstCombine/sub-gep.ll
Removed:
################################################################################
diff --git a/llvm/test/Transforms/InstCombine/sub-gep.ll b/llvm/test/Transforms/InstCombine/sub-gep.ll
index cf9604223f6c..fcb24eec349a 100644
--- a/llvm/test/Transforms/InstCombine/sub-gep.ll
+++ b/llvm/test/Transforms/InstCombine/sub-gep.ll
@@ -14,6 +14,32 @@ define i64 @test_inbounds([0 x i32]* %base, i64 %idx) {
ret i64 %d
}
+define i64 @test_partial_inbounds1([0 x i32]* %base, i64 %idx) {
+; CHECK-LABEL: @test_partial_inbounds1(
+; CHECK-NEXT: [[P2_IDX:%.*]] = shl i64 [[IDX:%.*]], 2
+; CHECK-NEXT: ret i64 [[P2_IDX]]
+;
+ %p1 = getelementptr inbounds [0 x i32], [0 x i32]* %base, i64 0, i64 0
+ %p2 = getelementptr [0 x i32], [0 x i32]* %base, i64 0, i64 %idx
+ %i1 = ptrtoint i32* %p1 to i64
+ %i2 = ptrtoint i32* %p2 to i64
+ %d = sub i64 %i2, %i1
+ ret i64 %d
+}
+
+define i64 @test_partial_inbounds2([0 x i32]* %base, i64 %idx) {
+; CHECK-LABEL: @test_partial_inbounds2(
+; CHECK-NEXT: [[P2_IDX:%.*]] = shl nsw i64 [[IDX:%.*]], 2
+; CHECK-NEXT: ret i64 [[P2_IDX]]
+;
+ %p1 = getelementptr [0 x i32], [0 x i32]* %base, i64 0, i64 0
+ %p2 = getelementptr inbounds [0 x i32], [0 x i32]* %base, i64 0, i64 %idx
+ %i1 = ptrtoint i32* %p1 to i64
+ %i2 = ptrtoint i32* %p2 to i64
+ %d = sub i64 %i2, %i1
+ ret i64 %d
+}
+
define i64 @test_inbounds_nuw([0 x i32]* %base, i64 %idx) {
; CHECK-LABEL: @test_inbounds_nuw(
; CHECK-NEXT: [[P2_IDX:%.*]] = shl nuw nsw i64 [[IDX:%.*]], 2
@@ -69,13 +95,39 @@ define i64 @test_inbounds_nuw_swapped([0 x i32]* %base, i64 %idx) {
ret i64 %d
}
+define i64 @test_inbounds1_nuw_swapped([0 x i32]* %base, i64 %idx) {
+; CHECK-LABEL: @test_inbounds1_nuw_swapped(
+; CHECK-NEXT: [[P2_IDX_NEG:%.*]] = mul i64 [[IDX:%.*]], -4
+; CHECK-NEXT: ret i64 [[P2_IDX_NEG]]
+;
+ %p1 = getelementptr inbounds [0 x i32], [0 x i32]* %base, i64 0, i64 0
+ %p2 = getelementptr [0 x i32], [0 x i32]* %base, i64 0, i64 %idx
+ %i1 = ptrtoint i32* %p2 to i64
+ %i2 = ptrtoint i32* %p1 to i64
+ %d = sub nuw i64 %i2, %i1
+ ret i64 %d
+}
+
+define i64 @test_inbounds2_nuw_swapped([0 x i32]* %base, i64 %idx) {
+; CHECK-LABEL: @test_inbounds2_nuw_swapped(
+; CHECK-NEXT: [[P2_IDX_NEG:%.*]] = mul i64 [[IDX:%.*]], -4
+; CHECK-NEXT: ret i64 [[P2_IDX_NEG]]
+;
+ %p1 = getelementptr [0 x i32], [0 x i32]* %base, i64 0, i64 0
+ %p2 = getelementptr inbounds [0 x i32], [0 x i32]* %base, i64 0, i64 %idx
+ %i1 = ptrtoint i32* %p2 to i64
+ %i2 = ptrtoint i32* %p1 to i64
+ %d = sub nuw i64 %i2, %i1
+ ret i64 %d
+}
+
; The sub and shl here could be nuw, but this is harder to handle.
define i64 @test_inbounds_nuw_two_gep([0 x i32]* %base, i64 %idx, i64 %idx2) {
; CHECK-LABEL: @test_inbounds_nuw_two_gep(
; CHECK-NEXT: [[P1_IDX_NEG:%.*]] = mul i64 [[IDX:%.*]], -4
; CHECK-NEXT: [[P2_IDX_NEG_NEG:%.*]] = shl i64 [[IDX2:%.*]], 2
-; CHECK-NEXT: [[DOTNEG:%.*]] = add i64 [[P2_IDX_NEG_NEG]], [[P1_IDX_NEG]]
-; CHECK-NEXT: ret i64 [[DOTNEG]]
+; CHECK-NEXT: [[GEPDIFF_NEG:%.*]] = add i64 [[P2_IDX_NEG_NEG]], [[P1_IDX_NEG]]
+; CHECK-NEXT: ret i64 [[GEPDIFF_NEG]]
;
%p1 = getelementptr inbounds [0 x i32], [0 x i32]* %base, i64 0, i64 %idx
%p2 = getelementptr inbounds [0 x i32], [0 x i32]* %base, i64 0, i64 %idx2
More information about the llvm-commits
mailing list