[llvm] 94f7d3d - [Test] Some more potential range check elimination opportunities
Max Kazantsev via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 16 00:00:52 PDT 2020
Author: Max Kazantsev
Date: 2020-09-16T14:00:19+07:00
New Revision: 94f7d3dba3c0a6ffd3e8a3f87ae849890578cd88
URL: https://github.com/llvm/llvm-project/commit/94f7d3dba3c0a6ffd3e8a3f87ae849890578cd88
DIFF: https://github.com/llvm/llvm-project/commit/94f7d3dba3c0a6ffd3e8a3f87ae849890578cd88.diff
LOG: [Test] Some more potential range check elimination opportunities
Added:
Modified:
llvm/test/Transforms/IndVarSimplify/predicated_ranges.ll
Removed:
################################################################################
diff --git a/llvm/test/Transforms/IndVarSimplify/predicated_ranges.ll b/llvm/test/Transforms/IndVarSimplify/predicated_ranges.ll
index 62a0a1dcf865..9aa714c8a56b 100644
--- a/llvm/test/Transforms/IndVarSimplify/predicated_ranges.ll
+++ b/llvm/test/Transforms/IndVarSimplify/predicated_ranges.ll
@@ -110,4 +110,241 @@ fail:
unreachable
}
+
+define void @predicated_outside_loop_signed(i32 %arg) nounwind #0 {
+; CHECK-LABEL: @predicated_outside_loop_signed(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: [[SUB1:%.*]] = sub nsw i32 [[ARG:%.*]], 1
+; CHECK-NEXT: [[CMP1:%.*]] = icmp slt i32 0, [[SUB1]]
+; CHECK-NEXT: br i1 [[CMP1]], label [[OUTER_PREHEADER:%.*]], label [[EXIT:%.*]]
+; CHECK: outer.preheader:
+; CHECK-NEXT: br label [[OUTER:%.*]]
+; CHECK: outer:
+; CHECK-NEXT: [[I:%.*]] = phi i32 [ [[I_INC:%.*]], [[OUTER_INC:%.*]] ], [ 0, [[OUTER_PREHEADER]] ]
+; CHECK-NEXT: [[SUB2:%.*]] = sub nsw i32 [[ARG]], [[I]]
+; CHECK-NEXT: [[SUB3:%.*]] = sub nsw i32 [[SUB2]], 1
+; CHECK-NEXT: [[CMP2:%.*]] = icmp slt i32 0, [[SUB3]]
+; CHECK-NEXT: br i1 [[CMP2]], label [[INNER_PH:%.*]], label [[OUTER_INC]]
+; CHECK: inner.ph:
+; CHECK-NEXT: br label [[INNER:%.*]]
+; CHECK: inner:
+; CHECK-NEXT: br i1 false, label [[INNER]], label [[OUTER_INC_LOOPEXIT:%.*]]
+; CHECK: outer.inc.loopexit:
+; CHECK-NEXT: br label [[OUTER_INC]]
+; CHECK: outer.inc:
+; CHECK-NEXT: [[I_INC]] = add nuw nsw i32 [[I]], 1
+; CHECK-NEXT: br i1 false, label [[OUTER]], label [[EXIT_LOOPEXIT:%.*]]
+; CHECK: exit.loopexit:
+; CHECK-NEXT: br label [[EXIT]]
+; CHECK: exit:
+; CHECK-NEXT: ret void
+;
+entry:
+ %sub1 = sub nsw i32 %arg, 1
+ %cmp1 = icmp slt i32 0, %sub1
+ br i1 %cmp1, label %outer, label %exit
+
+outer:
+ %i = phi i32 [ 0, %entry ], [ %i.inc, %outer.inc ]
+ %sub2 = sub nsw i32 %arg, %i
+ %sub3 = sub nsw i32 %sub2, 1
+ %cmp2 = icmp slt i32 0, %sub3
+ br i1 %cmp2, label %inner.ph, label %outer.inc
+
+inner.ph:
+ br label %inner
+
+inner:
+ %j = phi i32 [ 0, %inner.ph ], [ %j.inc, %inner ]
+ %j.inc = add nsw i32 %j, 1
+ %cmp3 = icmp slt i32 %j.inc, %sub3
+ br i1 %cmp3, label %inner, label %outer.inc
+
+outer.inc:
+ %i.inc = add nsw i32 %i, 1
+ %cmp4 = icmp slt i32 %i.inc, %arg
+ br i1 %cmp4, label %outer, label %exit
+
+exit:
+ ret void
+}
+
+define void @predicated_outside_loop_unsigned(i32 %arg) nounwind #0 {
+; CHECK-LABEL: @predicated_outside_loop_unsigned(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: [[SUB1:%.*]] = sub nsw i32 [[ARG:%.*]], 1
+; CHECK-NEXT: [[CMP1:%.*]] = icmp slt i32 0, [[SUB1]]
+; CHECK-NEXT: br i1 [[CMP1]], label [[OUTER_PREHEADER:%.*]], label [[EXIT:%.*]]
+; CHECK: outer.preheader:
+; CHECK-NEXT: br label [[OUTER:%.*]]
+; CHECK: outer:
+; CHECK-NEXT: [[I:%.*]] = phi i32 [ [[I_INC:%.*]], [[OUTER_INC:%.*]] ], [ 0, [[OUTER_PREHEADER]] ]
+; CHECK-NEXT: [[SUB2:%.*]] = sub nsw i32 [[ARG]], [[I]]
+; CHECK-NEXT: [[SUB3:%.*]] = sub nsw i32 [[SUB2]], 1
+; CHECK-NEXT: [[CMP2:%.*]] = icmp ult i32 0, [[SUB3]]
+; CHECK-NEXT: br i1 [[CMP2]], label [[INNER_PH:%.*]], label [[OUTER_INC]]
+; CHECK: inner.ph:
+; CHECK-NEXT: br label [[INNER:%.*]]
+; CHECK: inner:
+; CHECK-NEXT: br i1 false, label [[INNER]], label [[OUTER_INC_LOOPEXIT:%.*]]
+; CHECK: outer.inc.loopexit:
+; CHECK-NEXT: br label [[OUTER_INC]]
+; CHECK: outer.inc:
+; CHECK-NEXT: [[I_INC]] = add nuw nsw i32 [[I]], 1
+; CHECK-NEXT: br i1 false, label [[OUTER]], label [[EXIT_LOOPEXIT:%.*]]
+; CHECK: exit.loopexit:
+; CHECK-NEXT: br label [[EXIT]]
+; CHECK: exit:
+; CHECK-NEXT: ret void
+;
+entry:
+ %sub1 = sub nsw i32 %arg, 1
+ %cmp1 = icmp slt i32 0, %sub1
+ br i1 %cmp1, label %outer, label %exit
+
+outer:
+ %i = phi i32 [ 0, %entry ], [ %i.inc, %outer.inc ]
+ %sub2 = sub nsw i32 %arg, %i
+ %sub3 = sub nsw i32 %sub2, 1
+ %cmp2 = icmp ult i32 0, %sub3
+ br i1 %cmp2, label %inner.ph, label %outer.inc
+
+inner.ph:
+ br label %inner
+
+inner:
+ %j = phi i32 [ 0, %inner.ph ], [ %j.inc, %inner ]
+ %j.inc = add nsw i32 %j, 1
+ %cmp3 = icmp slt i32 %j.inc, %sub3
+ br i1 %cmp3, label %inner, label %outer.inc
+
+outer.inc:
+ %i.inc = add nsw i32 %i, 1
+ %cmp4 = icmp slt i32 %i.inc, %arg
+ br i1 %cmp4, label %outer, label %exit
+
+exit:
+ ret void
+}
+
+define void @predicated_inside_loop_signed(i32 %arg) nounwind #0 {
+; CHECK-LABEL: @predicated_inside_loop_signed(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: br label [[OUTER:%.*]]
+; CHECK: outer:
+; CHECK-NEXT: [[I:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[I_INC:%.*]], [[OUTER_INC:%.*]] ]
+; CHECK-NEXT: [[SUB1:%.*]] = sub nsw i32 [[ARG:%.*]], 1
+; CHECK-NEXT: [[CMP1:%.*]] = icmp slt i32 0, [[SUB1]]
+; CHECK-NEXT: br i1 [[CMP1]], label [[GUARDED:%.*]], label [[EXIT:%.*]]
+; CHECK: guarded:
+; CHECK-NEXT: [[SUB2:%.*]] = sub nsw i32 [[ARG]], [[I]]
+; CHECK-NEXT: [[SUB3:%.*]] = sub nsw i32 [[SUB2]], 1
+; CHECK-NEXT: [[CMP2:%.*]] = icmp slt i32 0, [[SUB3]]
+; CHECK-NEXT: br i1 [[CMP2]], label [[INNER_PH:%.*]], label [[OUTER_INC]]
+; CHECK: inner.ph:
+; CHECK-NEXT: br label [[INNER:%.*]]
+; CHECK: inner:
+; CHECK-NEXT: br i1 false, label [[INNER]], label [[OUTER_INC_LOOPEXIT:%.*]]
+; CHECK: outer.inc.loopexit:
+; CHECK-NEXT: br label [[OUTER_INC]]
+; CHECK: outer.inc:
+; CHECK-NEXT: [[I_INC]] = add nuw nsw i32 [[I]], 1
+; CHECK-NEXT: [[CMP4:%.*]] = icmp slt i32 [[I_INC]], [[ARG]]
+; CHECK-NEXT: br i1 [[CMP4]], label [[OUTER]], label [[EXIT]]
+; CHECK: exit:
+; CHECK-NEXT: ret void
+;
+entry:
+ br label %outer
+
+outer:
+ %i = phi i32 [ 0, %entry ], [ %i.inc, %outer.inc ]
+ %sub1 = sub nsw i32 %arg, 1
+ %cmp1 = icmp slt i32 0, %sub1
+ br i1 %cmp1, label %guarded, label %exit
+
+guarded:
+ %sub2 = sub nsw i32 %arg, %i
+ %sub3 = sub nsw i32 %sub2, 1
+ %cmp2 = icmp slt i32 0, %sub3
+ br i1 %cmp2, label %inner.ph, label %outer.inc
+
+inner.ph:
+ br label %inner
+
+inner:
+ %j = phi i32 [ 0, %inner.ph ], [ %j.inc, %inner ]
+ %j.inc = add nsw i32 %j, 1
+ %cmp3 = icmp slt i32 %j.inc, %sub3
+ br i1 %cmp3, label %inner, label %outer.inc
+
+outer.inc:
+ %i.inc = add nsw i32 %i, 1
+ %cmp4 = icmp slt i32 %i.inc, %arg
+ br i1 %cmp4, label %outer, label %exit
+
+exit:
+ ret void
+}
+
+define void @predicated_inside_loop_unsigned(i32 %arg) nounwind #0 {
+; CHECK-LABEL: @predicated_inside_loop_unsigned(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: br label [[OUTER:%.*]]
+; CHECK: outer:
+; CHECK-NEXT: [[I:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[I_INC:%.*]], [[OUTER_INC:%.*]] ]
+; CHECK-NEXT: [[SUB1:%.*]] = sub nsw i32 [[ARG:%.*]], 1
+; CHECK-NEXT: [[CMP1:%.*]] = icmp slt i32 0, [[SUB1]]
+; CHECK-NEXT: br i1 [[CMP1]], label [[GUARDED:%.*]], label [[EXIT:%.*]]
+; CHECK: guarded:
+; CHECK-NEXT: [[SUB2:%.*]] = sub nsw i32 [[ARG]], [[I]]
+; CHECK-NEXT: [[SUB3:%.*]] = sub nsw i32 [[SUB2]], 1
+; CHECK-NEXT: [[CMP2:%.*]] = icmp ult i32 0, [[SUB3]]
+; CHECK-NEXT: br i1 [[CMP2]], label [[INNER_PH:%.*]], label [[OUTER_INC]]
+; CHECK: inner.ph:
+; CHECK-NEXT: br label [[INNER:%.*]]
+; CHECK: inner:
+; CHECK-NEXT: br i1 false, label [[INNER]], label [[OUTER_INC_LOOPEXIT:%.*]]
+; CHECK: outer.inc.loopexit:
+; CHECK-NEXT: br label [[OUTER_INC]]
+; CHECK: outer.inc:
+; CHECK-NEXT: [[I_INC]] = add nuw nsw i32 [[I]], 1
+; CHECK-NEXT: [[CMP4:%.*]] = icmp slt i32 [[I_INC]], [[ARG]]
+; CHECK-NEXT: br i1 [[CMP4]], label [[OUTER]], label [[EXIT]]
+; CHECK: exit:
+; CHECK-NEXT: ret void
+;
+entry:
+ br label %outer
+
+outer:
+ %i = phi i32 [ 0, %entry ], [ %i.inc, %outer.inc ]
+ %sub1 = sub nsw i32 %arg, 1
+ %cmp1 = icmp slt i32 0, %sub1
+ br i1 %cmp1, label %guarded, label %exit
+
+guarded:
+ %sub2 = sub nsw i32 %arg, %i
+ %sub3 = sub nsw i32 %sub2, 1
+ %cmp2 = icmp ult i32 0, %sub3
+ br i1 %cmp2, label %inner.ph, label %outer.inc
+
+inner.ph:
+ br label %inner
+
+inner:
+ %j = phi i32 [ 0, %inner.ph ], [ %j.inc, %inner ]
+ %j.inc = add nsw i32 %j, 1
+ %cmp3 = icmp slt i32 %j.inc, %sub3
+ br i1 %cmp3, label %inner, label %outer.inc
+
+outer.inc:
+ %i.inc = add nsw i32 %i, 1
+ %cmp4 = icmp slt i32 %i.inc, %arg
+ br i1 %cmp4, label %outer, label %exit
+
+exit:
+ ret void
+}
+
!0 = !{i32 0, i32 2147483647}
More information about the llvm-commits
mailing list