summaryrefslogtreecommitdiffstats
path: root/llvm/test/Transforms/LoopPredication/widened.ll
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/test/Transforms/LoopPredication/widened.ll')
-rw-r--r--llvm/test/Transforms/LoopPredication/widened.ll150
1 files changed, 110 insertions, 40 deletions
diff --git a/llvm/test/Transforms/LoopPredication/widened.ll b/llvm/test/Transforms/LoopPredication/widened.ll
index 33c4e270613..374c74c1af5 100644
--- a/llvm/test/Transforms/LoopPredication/widened.ll
+++ b/llvm/test/Transforms/LoopPredication/widened.ll
@@ -1,3 +1,4 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt -S -loop-predication -loop-predication-enable-iv-truncation=true < %s 2>&1 | FileCheck %s
declare void @llvm.experimental.guard(i1, ...)
@@ -7,25 +8,49 @@ declare i16 @short_length(i8*)
; Consider range check of type i16 and i32, while IV is of type i64
; We can loop predicate this because the IV range is within i16 and within i32.
define i64 @iv_wider_type_rc_two_narrow_types(i32 %offA, i16 %offB, i8* %arrA, i8* %arrB) {
-; CHECK-LABEL: iv_wider_type_rc_two_narrow_types
+; CHECK-LABEL: @iv_wider_type_rc_two_narrow_types(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: [[LENGTHA:%.*]] = call i32 @length(i8* [[ARRA:%.*]])
+; CHECK-NEXT: [[LENGTHB:%.*]] = call i16 @short_length(i8* [[ARRB:%.*]])
+; CHECK-NEXT: [[TMP0:%.*]] = sub i16 [[LENGTHB]], [[OFFB:%.*]]
+; CHECK-NEXT: [[TMP1:%.*]] = icmp ule i16 16, [[TMP0]]
+; CHECK-NEXT: [[TMP2:%.*]] = icmp ult i16 [[OFFB]], [[LENGTHB]]
+; CHECK-NEXT: [[TMP3:%.*]] = and i1 [[TMP2]], [[TMP1]]
+; CHECK-NEXT: [[TMP4:%.*]] = sub i32 [[LENGTHA]], [[OFFA:%.*]]
+; CHECK-NEXT: [[TMP5:%.*]] = icmp ule i32 16, [[TMP4]]
+; CHECK-NEXT: [[TMP6:%.*]] = icmp ult i32 [[OFFA]], [[LENGTHA]]
+; CHECK-NEXT: [[TMP7:%.*]] = and i1 [[TMP6]], [[TMP5]]
+; CHECK-NEXT: br label [[LOOP:%.*]]
+; CHECK: loop:
+; CHECK-NEXT: [[IV:%.*]] = phi i64 [ 0, [[ENTRY:%.*]] ], [ [[IV_NEXT:%.*]], [[LOOP]] ]
+; CHECK-NEXT: [[IV_TRUNC_32:%.*]] = trunc i64 [[IV]] to i32
+; CHECK-NEXT: [[IV_TRUNC_16:%.*]] = trunc i64 [[IV]] to i16
+; CHECK-NEXT: [[INDEXA:%.*]] = add i32 [[IV_TRUNC_32]], [[OFFA]]
+; CHECK-NEXT: [[INDEXB:%.*]] = add i16 [[IV_TRUNC_16]], [[OFFB]]
+; CHECK-NEXT: [[RCA:%.*]] = icmp ult i32 [[INDEXA]], [[LENGTHA]]
+; CHECK-NEXT: [[RCB:%.*]] = icmp ult i16 [[INDEXB]], [[LENGTHB]]
+; CHECK-NEXT: [[WIDE_CHK:%.*]] = and i1 [[RCA]], [[RCB]]
+; CHECK-NEXT: [[TMP8:%.*]] = and i1 [[TMP3]], [[TMP7]]
+; CHECK-NEXT: call void (i1, ...) @llvm.experimental.guard(i1 [[TMP8]], i32 9) [ "deopt"() ]
+; CHECK-NEXT: [[INDEXA_EXT:%.*]] = zext i32 [[INDEXA]] to i64
+; CHECK-NEXT: [[ADDRA:%.*]] = getelementptr inbounds i8, i8* [[ARRA]], i64 [[INDEXA_EXT]]
+; CHECK-NEXT: [[ELTA:%.*]] = load i8, i8* [[ADDRA]]
+; CHECK-NEXT: [[INDEXB_EXT:%.*]] = zext i16 [[INDEXB]] to i64
+; CHECK-NEXT: [[ADDRB:%.*]] = getelementptr inbounds i8, i8* [[ARRB]], i64 [[INDEXB_EXT]]
+; CHECK-NEXT: store i8 [[ELTA]], i8* [[ADDRB]]
+; CHECK-NEXT: [[IV_NEXT]] = add nuw nsw i64 [[IV]], 1
+; CHECK-NEXT: [[LATCH_CHECK:%.*]] = icmp ult i64 [[IV_NEXT]], 16
+; CHECK-NEXT: br i1 [[LATCH_CHECK]], label [[LOOP]], label [[EXIT:%.*]]
+; CHECK: exit:
+; CHECK-NEXT: [[IV_LCSSA:%.*]] = phi i64 [ [[IV]], [[LOOP]] ]
+; CHECK-NEXT: ret i64 [[IV_LCSSA]]
+;
entry:
-; CHECK-LABEL: entry:
-; CHECK: [[idxB:[^ ]+]] = sub i16 %lengthB, %offB
-; CHECK-NEXT: [[limit_checkB:[^ ]+]] = icmp ule i16 16, [[idxB]]
-; CHECK-NEXT: [[first_iteration_checkB:[^ ]+]] = icmp ult i16 %offB, %lengthB
-; CHECK-NEXT: [[WideChkB:[^ ]+]] = and i1 [[first_iteration_checkB]], [[limit_checkB]]
-; CHECK-NEXT: [[idxA:[^ ]+]] = sub i32 %lengthA, %offA
-; CHECK-NEXT: [[limit_checkA:[^ ]+]] = icmp ule i32 16, [[idxA]]
-; CHECK-NEXT: [[first_iteration_checkA:[^ ]+]] = icmp ult i32 %offA, %lengthA
-; CHECK-NEXT: [[WideChkA:[^ ]+]] = and i1 [[first_iteration_checkA]], [[limit_checkA]]
%lengthA = call i32 @length(i8* %arrA)
%lengthB = call i16 @short_length(i8* %arrB)
- br label %loop
+ br label %loop
loop:
-; CHECK-LABEL: loop:
-; CHECK: [[invariant_check:[^ ]+]] = and i1 [[WideChkB]], [[WideChkA]]
-; CHECK-NEXT: call void (i1, ...) @llvm.experimental.guard(i1 [[invariant_check]], i32 9)
%iv = phi i64 [0, %entry ], [ %iv.next, %loop ]
%iv.trunc.32 = trunc i64 %iv to i32
%iv.trunc.16 = trunc i64 %iv to i16
@@ -46,40 +71,67 @@ loop:
br i1 %latch.check, label %loop, label %exit
exit:
- ret i64 %iv
+ ret i64 %iv
}
; Consider an IV of type long and an array access into int array.
; IV is of type i64 while the range check operands are of type i32 and i64.
define i64 @iv_rc_different_types(i32 %offA, i32 %offB, i8* %arrA, i8* %arrB, i64 %max)
+; CHECK-LABEL: @iv_rc_different_types(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: [[LENGTHA:%.*]] = call i32 @length(i8* [[ARRA:%.*]])
+; CHECK-NEXT: [[LENGTHB:%.*]] = call i32 @length(i8* [[ARRB:%.*]])
+; CHECK-NEXT: [[TMP0:%.*]] = add i32 [[LENGTHB]], -1
+; CHECK-NEXT: [[TMP1:%.*]] = sub i32 [[TMP0]], [[OFFB:%.*]]
+; CHECK-NEXT: [[TMP2:%.*]] = icmp ule i32 15, [[TMP1]]
+; CHECK-NEXT: [[TMP3:%.*]] = icmp ult i32 [[OFFB]], [[LENGTHB]]
+; CHECK-NEXT: [[TMP4:%.*]] = and i1 [[TMP3]], [[TMP2]]
+; CHECK-NEXT: [[TMP5:%.*]] = add i64 [[MAX:%.*]], -1
+; CHECK-NEXT: [[TMP6:%.*]] = icmp ule i64 15, [[TMP5]]
+; CHECK-NEXT: [[TMP7:%.*]] = icmp ult i64 0, [[MAX]]
+; CHECK-NEXT: [[TMP8:%.*]] = and i1 [[TMP7]], [[TMP6]]
+; CHECK-NEXT: [[TMP9:%.*]] = add i32 [[LENGTHA]], -1
+; CHECK-NEXT: [[TMP10:%.*]] = sub i32 [[TMP9]], [[OFFA:%.*]]
+; CHECK-NEXT: [[TMP11:%.*]] = icmp ule i32 15, [[TMP10]]
+; CHECK-NEXT: [[TMP12:%.*]] = icmp ult i32 [[OFFA]], [[LENGTHA]]
+; CHECK-NEXT: [[TMP13:%.*]] = and i1 [[TMP12]], [[TMP11]]
+; CHECK-NEXT: br label [[LOOP:%.*]]
+; CHECK: loop:
+; CHECK-NEXT: [[IV:%.*]] = phi i64 [ 0, [[ENTRY:%.*]] ], [ [[IV_NEXT:%.*]], [[LOOP]] ]
+; CHECK-NEXT: [[IV_TRUNC:%.*]] = trunc i64 [[IV]] to i32
+; CHECK-NEXT: [[INDEXA:%.*]] = add i32 [[IV_TRUNC]], [[OFFA]]
+; CHECK-NEXT: [[INDEXB:%.*]] = add i32 [[IV_TRUNC]], [[OFFB]]
+; CHECK-NEXT: [[RCA:%.*]] = icmp ult i32 [[INDEXA]], [[LENGTHA]]
+; CHECK-NEXT: [[RCIV:%.*]] = icmp ult i64 [[IV]], [[MAX]]
+; CHECK-NEXT: [[WIDE_CHK:%.*]] = and i1 [[RCA]], [[RCIV]]
+; CHECK-NEXT: [[RCB:%.*]] = icmp ult i32 [[INDEXB]], [[LENGTHB]]
+; CHECK-NEXT: [[WIDE_CHK_FINAL:%.*]] = and i1 [[WIDE_CHK]], [[RCB]]
+; CHECK-NEXT: [[TMP14:%.*]] = and i1 [[TMP4]], [[TMP8]]
+; CHECK-NEXT: [[TMP15:%.*]] = and i1 [[TMP14]], [[TMP13]]
+; CHECK-NEXT: call void (i1, ...) @llvm.experimental.guard(i1 [[TMP15]], i32 9) [ "deopt"() ]
+; CHECK-NEXT: [[INDEXA_EXT:%.*]] = zext i32 [[INDEXA]] to i64
+; CHECK-NEXT: [[ADDRA:%.*]] = getelementptr inbounds i8, i8* [[ARRA]], i64 [[INDEXA_EXT]]
+; CHECK-NEXT: [[ELTA:%.*]] = load i8, i8* [[ADDRA]]
+; CHECK-NEXT: [[INDEXB_EXT:%.*]] = zext i32 [[INDEXB]] to i64
+; CHECK-NEXT: [[ADDRB:%.*]] = getelementptr inbounds i8, i8* [[ARRB]], i64 [[INDEXB_EXT]]
+; CHECK-NEXT: [[ELTB:%.*]] = load i8, i8* [[ADDRB]]
+; CHECK-NEXT: [[RESULT:%.*]] = xor i8 [[ELTA]], [[ELTB]]
+; CHECK-NEXT: store i8 [[RESULT]], i8* [[ADDRA]]
+; CHECK-NEXT: [[IV_NEXT]] = add nuw nsw i64 [[IV]], 1
+; CHECK-NEXT: [[LATCH_CHECK:%.*]] = icmp ult i64 [[IV]], 15
+; CHECK-NEXT: br i1 [[LATCH_CHECK]], label [[LOOP]], label [[EXIT:%.*]]
+; CHECK: exit:
+; CHECK-NEXT: [[IV_LCSSA:%.*]] = phi i64 [ [[IV]], [[LOOP]] ]
+; CHECK-NEXT: ret i64 [[IV_LCSSA]]
+;
{
-; CHECK-LABEL: iv_rc_different_types
entry:
-; CHECK-LABEL: entry:
-; CHECK: [[lenB:[^ ]+]] = add i32 %lengthB, -1
-; CHECK-NEXT: [[idxB:[^ ]+]] = sub i32 [[lenB]], %offB
-; CHECK-NEXT: [[limit_checkB:[^ ]+]] = icmp ule i32 15, [[idxB]]
-; CHECK-NEXT: [[first_iteration_checkB:[^ ]+]] = icmp ult i32 %offB, %lengthB
-; CHECK-NEXT: [[WideChkB:[^ ]+]] = and i1 [[first_iteration_checkB]], [[limit_checkB]]
-; CHECK-NEXT: [[maxMinusOne:[^ ]+]] = add i64 %max, -1
-; CHECK-NEXT: [[limit_checkMax:[^ ]+]] = icmp ule i64 15, [[maxMinusOne]]
-; CHECK-NEXT: [[first_iteration_checkMax:[^ ]+]] = icmp ult i64 0, %max
-; CHECK-NEXT: [[WideChkMax:[^ ]+]] = and i1 [[first_iteration_checkMax]], [[limit_checkMax]]
-; CHECK-NEXT: [[lenA:[^ ]+]] = add i32 %lengthA, -1
-; CHECK-NEXT: [[idxA:[^ ]+]] = sub i32 [[lenA]], %offA
-; CHECK-NEXT: [[limit_checkA:[^ ]+]] = icmp ule i32 15, [[idxA]]
-; CHECK-NEXT: [[first_iteration_checkA:[^ ]+]] = icmp ult i32 %offA, %lengthA
-; CHECK-NEXT: [[WideChkA:[^ ]+]] = and i1 [[first_iteration_checkA]], [[limit_checkA]]
%lengthA = call i32 @length(i8* %arrA)
%lengthB = call i32 @length(i8* %arrB)
br label %loop
loop:
-; CHECK-LABEL: loop:
-; CHECK: [[BandMax:[^ ]+]] = and i1 [[WideChkB]], [[WideChkMax]]
-; CHECK: [[ABandMax:[^ ]+]] = and i1 [[BandMax]], [[WideChkA]]
-; CHECK: call void (i1, ...) @llvm.experimental.guard(i1 [[ABandMax]], i32 9)
%iv = phi i64 [0, %entry ], [ %iv.next, %loop ]
%iv.trunc = trunc i64 %iv to i32
%indexA = add i32 %iv.trunc, %offA
@@ -110,15 +162,33 @@ exit:
; for (i64 i= 5; i>= 2; i++)
; this loop wraps around after reaching 2^64.
define i64 @iv_rc_different_type(i32 %offA, i8* %arrA) {
-; CHECK-LABEL: iv_rc_different_type
+; CHECK-LABEL: @iv_rc_different_type(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: [[LENGTHA:%.*]] = call i32 @length(i8* [[ARRA:%.*]])
+; CHECK-NEXT: br label [[LOOP:%.*]]
+; CHECK: loop:
+; CHECK-NEXT: [[IV:%.*]] = phi i64 [ 5, [[ENTRY:%.*]] ], [ [[IV_NEXT:%.*]], [[LOOP]] ]
+; CHECK-NEXT: [[IV_TRUNC_32:%.*]] = trunc i64 [[IV]] to i32
+; CHECK-NEXT: [[INDEXA:%.*]] = add i32 [[IV_TRUNC_32]], [[OFFA:%.*]]
+; CHECK-NEXT: [[RCA:%.*]] = icmp ult i32 [[INDEXA]], [[LENGTHA]]
+; CHECK-NEXT: call void (i1, ...) @llvm.experimental.guard(i1 [[RCA]], i32 9) [ "deopt"() ]
+; CHECK-NEXT: [[INDEXA_EXT:%.*]] = zext i32 [[INDEXA]] to i64
+; CHECK-NEXT: [[ADDRA:%.*]] = getelementptr inbounds i8, i8* [[ARRA]], i64 [[INDEXA_EXT]]
+; CHECK-NEXT: [[ELTA:%.*]] = load i8, i8* [[ADDRA]]
+; CHECK-NEXT: [[RES:%.*]] = add i8 [[ELTA]], 2
+; CHECK-NEXT: store i8 [[ELTA]], i8* [[ADDRA]]
+; CHECK-NEXT: [[IV_NEXT]] = add i64 [[IV]], 1
+; CHECK-NEXT: [[LATCH_CHECK:%.*]] = icmp sge i64 [[IV_NEXT]], 2
+; CHECK-NEXT: br i1 [[LATCH_CHECK]], label [[LOOP]], label [[EXIT:%.*]]
+; CHECK: exit:
+; CHECK-NEXT: [[IV_LCSSA:%.*]] = phi i64 [ [[IV]], [[LOOP]] ]
+; CHECK-NEXT: ret i64 [[IV_LCSSA]]
+;
entry:
%lengthA = call i32 @length(i8* %arrA)
br label %loop
loop:
-; CHECK-LABEL: loop:
-; CHECK: %rcA = icmp ult i32 %indexA, %lengthA
-; CHECK-NEXT: call void (i1, ...) @llvm.experimental.guard(i1 %rcA, i32 9)
%iv = phi i64 [ 5, %entry ], [ %iv.next, %loop ]
%iv.trunc.32 = trunc i64 %iv to i32
%indexA = add i32 %iv.trunc.32, %offA
@@ -134,5 +204,5 @@ loop:
br i1 %latch.check, label %loop, label %exit
exit:
- ret i64 %iv
+ ret i64 %iv
}
OpenPOWER on IntegriCloud