[llvm] 1a1aed8 - [InstCombine] add tests for icmp-gep; NFC
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 28 07:03:09 PDT 2021
Author: Sanjay Patel
Date: 2021-09-28T10:00:35-04:00
New Revision: 1a1aed8da8c19fd58a7208be9ab5bf185474392b
URL: https://github.com/llvm/llvm-project/commit/1a1aed8da8c19fd58a7208be9ab5bf185474392b
DIFF: https://github.com/llvm/llvm-project/commit/1a1aed8da8c19fd58a7208be9ab5bf185474392b.diff
LOG: [InstCombine] add tests for icmp-gep; NFC
We need more coverage for commuted and (un)signed preds to
verify that things behave as expected here. Currently, we
do not transform signed preds or non-inbounds geps.
Added:
Modified:
llvm/test/Transforms/InstCombine/icmp-gep.ll
Removed:
################################################################################
diff --git a/llvm/test/Transforms/InstCombine/icmp-gep.ll b/llvm/test/Transforms/InstCombine/icmp-gep.ll
index 3b54e4d9b8b7..d8bbd394a026 100644
--- a/llvm/test/Transforms/InstCombine/icmp-gep.ll
+++ b/llvm/test/Transforms/InstCombine/icmp-gep.ll
@@ -52,14 +52,62 @@ define i1 @eq_base_inbounds_commute(i64 %y) {
ret i1 %r
}
-define i1 @sgt_base(i8* %x, i64 %y) {
-; CHECK-LABEL: @sgt_base(
+define i1 @slt_base(i8* %x, i64 %y) {
+; CHECK-LABEL: @slt_base(
; CHECK-NEXT: [[G:%.*]] = getelementptr i8, i8* [[X:%.*]], i64 [[Y:%.*]]
-; CHECK-NEXT: [[R:%.*]] = icmp sgt i8* [[G]], [[X]]
+; CHECK-NEXT: [[R:%.*]] = icmp slt i8* [[G]], [[X]]
; CHECK-NEXT: ret i1 [[R]]
;
%g = getelementptr i8, i8* %x, i64 %y
- %r = icmp sgt i8* %g, %x
+ %r = icmp slt i8* %g, %x
+ ret i1 %r
+}
+
+define i1 @sgt_base_commute(i64 %y) {
+; CHECK-LABEL: @sgt_base_commute(
+; CHECK-NEXT: [[X:%.*]] = call i8* @getptr()
+; CHECK-NEXT: [[G:%.*]] = getelementptr i8, i8* [[X]], i64 [[Y:%.*]]
+; CHECK-NEXT: [[R:%.*]] = icmp sgt i8* [[X]], [[G]]
+; CHECK-NEXT: ret i1 [[R]]
+;
+ %x = call i8* @getptr() ; thwart complexity-based canonicalization
+ %g = getelementptr i8, i8* %x, i64 %y
+ %r = icmp sgt i8* %x, %g
+ ret i1 %r
+}
+
+define i1 @slt_base_inbounds(i8* %x, i64 %y) {
+; CHECK-LABEL: @slt_base_inbounds(
+; CHECK-NEXT: [[G:%.*]] = getelementptr inbounds i8, i8* [[X:%.*]], i64 [[Y:%.*]]
+; CHECK-NEXT: [[R:%.*]] = icmp slt i8* [[G]], [[X]]
+; CHECK-NEXT: ret i1 [[R]]
+;
+ %g = getelementptr inbounds i8, i8* %x, i64 %y
+ %r = icmp slt i8* %g, %x
+ ret i1 %r
+}
+
+define i1 @sgt_base_inbounds_commute(i64 %y) {
+; CHECK-LABEL: @sgt_base_inbounds_commute(
+; CHECK-NEXT: [[X:%.*]] = call i8* @getptr()
+; CHECK-NEXT: [[G:%.*]] = getelementptr inbounds i8, i8* [[X]], i64 [[Y:%.*]]
+; CHECK-NEXT: [[R:%.*]] = icmp sgt i8* [[X]], [[G]]
+; CHECK-NEXT: ret i1 [[R]]
+;
+ %x = call i8* @getptr() ; thwart complexity-based canonicalization
+ %g = getelementptr inbounds i8, i8* %x, i64 %y
+ %r = icmp sgt i8* %x, %g
+ ret i1 %r
+}
+
+define i1 @ult_base(i8* %x, i64 %y) {
+; CHECK-LABEL: @ult_base(
+; CHECK-NEXT: [[G:%.*]] = getelementptr i8, i8* [[X:%.*]], i64 [[Y:%.*]]
+; CHECK-NEXT: [[R:%.*]] = icmp ult i8* [[G]], [[X]]
+; CHECK-NEXT: ret i1 [[R]]
+;
+ %g = getelementptr i8, i8* %x, i64 %y
+ %r = icmp ult i8* %g, %x
ret i1 %r
}
@@ -86,16 +134,15 @@ define i1 @ult_base_inbounds(i8* %x, i64 %y) {
ret i1 %r
}
-define i1 @slt_base_inbounds_commute(i64 %y) {
-; CHECK-LABEL: @slt_base_inbounds_commute(
+define i1 @ugt_base_inbounds_commute(i64 %y) {
+; CHECK-LABEL: @ugt_base_inbounds_commute(
; CHECK-NEXT: [[X:%.*]] = call i8* @getptr()
-; CHECK-NEXT: [[G:%.*]] = getelementptr inbounds i8, i8* [[X]], i64 [[Y:%.*]]
-; CHECK-NEXT: [[R:%.*]] = icmp slt i8* [[X]], [[G]]
+; CHECK-NEXT: [[R:%.*]] = icmp slt i64 [[Y:%.*]], 0
; CHECK-NEXT: ret i1 [[R]]
;
%x = call i8* @getptr() ; thwart complexity-based canonicalization
%g = getelementptr inbounds i8, i8* %x, i64 %y
- %r = icmp slt i8* %x, %g
+ %r = icmp ugt i8* %x, %g
ret i1 %r
}
More information about the llvm-commits
mailing list