Extend handleMultiUseReductions to support strict predicates (>, <), matching the first index instead of the last for non-strict predicates. Builds on top of https://github.com/llvm/llvm-project/pull/141431. FindLast reductions with strict predicates are adjusted to compute the correct result as follows: 1. Find the first canonical indices corresponding to partial min/max values, using loop reductions. 2. Find which of the partial min/max values are equal to the overall min/max value. 3. Select among the canonical indices those corresponding to the overall min/max value. 4. Find the first canonical index of overall min/max and scale it back to the original IV using VPDerivedIVRecipe. 5. If the overall min/max equals the starting min/max, the condition in the loop was always false, due to being strict; return the original start value in that case.
370 lines
19 KiB
LLVM
370 lines
19 KiB
LLVM
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 6
|
|
; RUN: opt -passes=loop-vectorize -force-vector-width=4 -force-vector-interleave=1 -S < %s | FileCheck %s --check-prefix=CHECK
|
|
; RUN: opt -passes=loop-vectorize -force-vector-width=4 -force-vector-interleave=4 -S < %s | FileCheck %s --check-prefix=CHECK
|
|
; RUN: opt -passes=loop-vectorize -force-vector-width=1 -force-vector-interleave=4 -S < %s | FileCheck %s --check-prefix=CHECK
|
|
|
|
define i64 @smax_idx(ptr nocapture readonly %a, i64 %mm, i64 %ii, ptr nocapture writeonly %res_max, i64 %n) {
|
|
; CHECK-LABEL: define i64 @smax_idx(
|
|
; CHECK-SAME: ptr readonly captures(none) [[A:%.*]], i64 [[MM:%.*]], i64 [[II:%.*]], ptr writeonly captures(none) [[RES_MAX:%.*]], i64 [[N:%.*]]) {
|
|
; CHECK-NEXT: [[ENTRY:.*]]:
|
|
; CHECK-NEXT: br label %[[FOR_BODY:.*]]
|
|
; CHECK: [[FOR_BODY]]:
|
|
; CHECK-NEXT: [[INDVARS_IV:%.*]] = phi i64 [ 0, %[[ENTRY]] ], [ [[INDVARS_IV_NEXT:%.*]], %[[FOR_BODY]] ]
|
|
; CHECK-NEXT: [[MAX_09:%.*]] = phi i64 [ [[MM]], %[[ENTRY]] ], [ [[TMP1:%.*]], %[[FOR_BODY]] ]
|
|
; CHECK-NEXT: [[IDX_011:%.*]] = phi i64 [ [[II]], %[[ENTRY]] ], [ [[SPEC_SELECT7:%.*]], %[[FOR_BODY]] ]
|
|
; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds i64, ptr [[A]], i64 [[INDVARS_IV]]
|
|
; CHECK-NEXT: [[TMP0:%.*]] = load i64, ptr [[ARRAYIDX]], align 4
|
|
; CHECK-NEXT: [[TMP1]] = tail call i64 @llvm.smax.i64(i64 [[MAX_09]], i64 [[TMP0]])
|
|
; CHECK-NEXT: [[CMP1:%.*]] = icmp slt i64 [[MAX_09]], [[TMP0]]
|
|
; CHECK-NEXT: [[SPEC_SELECT7]] = select i1 [[CMP1]], i64 [[INDVARS_IV]], i64 [[IDX_011]]
|
|
; CHECK-NEXT: [[INDVARS_IV_NEXT]] = add nuw nsw i64 [[INDVARS_IV]], 1
|
|
; CHECK-NEXT: [[EXITCOND_NOT:%.*]] = icmp eq i64 [[INDVARS_IV_NEXT]], [[N]]
|
|
; CHECK-NEXT: br i1 [[EXITCOND_NOT]], label %[[EXIT:.*]], label %[[FOR_BODY]]
|
|
; CHECK: [[EXIT]]:
|
|
; CHECK-NEXT: [[DOTLCSSA:%.*]] = phi i64 [ [[TMP1]], %[[FOR_BODY]] ]
|
|
; CHECK-NEXT: [[SPEC_SELECT7_LCSSA:%.*]] = phi i64 [ [[SPEC_SELECT7]], %[[FOR_BODY]] ]
|
|
; CHECK-NEXT: store i64 [[DOTLCSSA]], ptr [[RES_MAX]], align 4
|
|
; CHECK-NEXT: ret i64 [[SPEC_SELECT7_LCSSA]]
|
|
;
|
|
entry:
|
|
br label %for.body
|
|
|
|
for.body:
|
|
%indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ]
|
|
%max.09 = phi i64 [ %mm, %entry ], [ %1, %for.body ]
|
|
%idx.011 = phi i64 [ %ii, %entry ], [ %spec.select7, %for.body ]
|
|
%arrayidx = getelementptr inbounds i64, ptr %a, i64 %indvars.iv
|
|
%0 = load i64, ptr %arrayidx
|
|
%1 = tail call i64 @llvm.smax.i64(i64 %max.09, i64 %0)
|
|
%cmp1 = icmp slt i64 %max.09, %0
|
|
%spec.select7 = select i1 %cmp1, i64 %indvars.iv, i64 %idx.011
|
|
%indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
|
|
%exitcond.not = icmp eq i64 %indvars.iv.next, %n
|
|
br i1 %exitcond.not, label %exit, label %for.body
|
|
|
|
exit:
|
|
store i64 %1, ptr %res_max
|
|
ret i64 %spec.select7
|
|
}
|
|
|
|
;
|
|
; Check the different order of reduction phis.
|
|
;
|
|
define i64 @smax_idx_inverted_phi(ptr nocapture readonly %a, i64 %mm, i64 %ii, ptr nocapture writeonly %res_max, i64 %n) {
|
|
; CHECK-LABEL: define i64 @smax_idx_inverted_phi(
|
|
; CHECK-SAME: ptr readonly captures(none) [[A:%.*]], i64 [[MM:%.*]], i64 [[II:%.*]], ptr writeonly captures(none) [[RES_MAX:%.*]], i64 [[N:%.*]]) {
|
|
; CHECK-NEXT: [[ENTRY:.*]]:
|
|
; CHECK-NEXT: br label %[[FOR_BODY:.*]]
|
|
; CHECK: [[FOR_BODY]]:
|
|
; CHECK-NEXT: [[INDVARS_IV:%.*]] = phi i64 [ 0, %[[ENTRY]] ], [ [[INDVARS_IV_NEXT:%.*]], %[[FOR_BODY]] ]
|
|
; CHECK-NEXT: [[IDX_011:%.*]] = phi i64 [ [[II]], %[[ENTRY]] ], [ [[SPEC_SELECT7:%.*]], %[[FOR_BODY]] ]
|
|
; CHECK-NEXT: [[MAX_09:%.*]] = phi i64 [ [[MM]], %[[ENTRY]] ], [ [[TMP1:%.*]], %[[FOR_BODY]] ]
|
|
; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds i64, ptr [[A]], i64 [[INDVARS_IV]]
|
|
; CHECK-NEXT: [[TMP0:%.*]] = load i64, ptr [[ARRAYIDX]], align 4
|
|
; CHECK-NEXT: [[TMP1]] = tail call i64 @llvm.smax.i64(i64 [[MAX_09]], i64 [[TMP0]])
|
|
; CHECK-NEXT: [[CMP1:%.*]] = icmp slt i64 [[MAX_09]], [[TMP0]]
|
|
; CHECK-NEXT: [[SPEC_SELECT7]] = select i1 [[CMP1]], i64 [[INDVARS_IV]], i64 [[IDX_011]]
|
|
; CHECK-NEXT: [[INDVARS_IV_NEXT]] = add nuw nsw i64 [[INDVARS_IV]], 1
|
|
; CHECK-NEXT: [[EXITCOND_NOT:%.*]] = icmp eq i64 [[INDVARS_IV_NEXT]], [[N]]
|
|
; CHECK-NEXT: br i1 [[EXITCOND_NOT]], label %[[EXIT:.*]], label %[[FOR_BODY]]
|
|
; CHECK: [[EXIT]]:
|
|
; CHECK-NEXT: [[DOTLCSSA:%.*]] = phi i64 [ [[TMP1]], %[[FOR_BODY]] ]
|
|
; CHECK-NEXT: [[SPEC_SELECT7_LCSSA:%.*]] = phi i64 [ [[SPEC_SELECT7]], %[[FOR_BODY]] ]
|
|
; CHECK-NEXT: store i64 [[DOTLCSSA]], ptr [[RES_MAX]], align 4
|
|
; CHECK-NEXT: ret i64 [[SPEC_SELECT7_LCSSA]]
|
|
;
|
|
entry:
|
|
br label %for.body
|
|
|
|
for.body:
|
|
%indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ]
|
|
%idx.011 = phi i64 [ %ii, %entry ], [ %spec.select7, %for.body ]
|
|
%max.09 = phi i64 [ %mm, %entry ], [ %1, %for.body ]
|
|
%arrayidx = getelementptr inbounds i64, ptr %a, i64 %indvars.iv
|
|
%0 = load i64, ptr %arrayidx
|
|
%1 = tail call i64 @llvm.smax.i64(i64 %max.09, i64 %0)
|
|
%cmp1 = icmp slt i64 %max.09, %0
|
|
%spec.select7 = select i1 %cmp1, i64 %indvars.iv, i64 %idx.011
|
|
%indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
|
|
%exitcond.not = icmp eq i64 %indvars.iv.next, %n
|
|
br i1 %exitcond.not, label %exit, label %for.body
|
|
|
|
exit:
|
|
store i64 %1, ptr %res_max
|
|
ret i64 %spec.select7
|
|
}
|
|
|
|
; Check if it is a min/max with index (MMI) pattern when the
|
|
; min/max value is not used outside the loop.
|
|
;
|
|
; Currently, the vectorizer checks if smax value is used outside
|
|
; the loop. However, even if only the index part has external users,
|
|
; and smax itself does not have external users, it can still form a
|
|
; MMI pattern.
|
|
;
|
|
define i64 @smax_idx_max_no_exit_user(ptr nocapture readonly %a, i64 %mm, i64 %ii, i64 %n) {
|
|
entry:
|
|
br label %for.body
|
|
|
|
for.body:
|
|
%indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ]
|
|
%max.09 = phi i64 [ %mm, %entry ], [ %1, %for.body ]
|
|
%idx.011 = phi i64 [ %ii, %entry ], [ %spec.select7, %for.body ]
|
|
%arrayidx = getelementptr inbounds i64, ptr %a, i64 %indvars.iv
|
|
%0 = load i64, ptr %arrayidx
|
|
%1 = tail call i64 @llvm.smax.i64(i64 %max.09, i64 %0)
|
|
%cmp1 = icmp slt i64 %max.09, %0
|
|
%spec.select7 = select i1 %cmp1, i64 %indvars.iv, i64 %idx.011
|
|
%indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
|
|
%exitcond.not = icmp eq i64 %indvars.iv.next, %n
|
|
br i1 %exitcond.not, label %exit, label %for.body
|
|
|
|
exit:
|
|
; %1 has no external users
|
|
ret i64 %spec.select7
|
|
}
|
|
|
|
; Check smax implemented by select(cmp()).
|
|
;
|
|
; Currently, MMI pattern does not support icmp with multiple users.
|
|
; TODO: It may be possible to reuse some of the methods in instcombine pass to
|
|
; check whether icmp can be duplicated.
|
|
;
|
|
define i64 @smax_idx_select_cmp(ptr nocapture readonly %a, i64 %mm, i64 %ii, ptr nocapture writeonly %res_max, i64 %n) {
|
|
; CHECK-LABEL: define i64 @smax_idx_select_cmp(
|
|
; CHECK-SAME: ptr readonly captures(none) [[A:%.*]], i64 [[MM:%.*]], i64 [[II:%.*]], ptr writeonly captures(none) [[RES_MAX:%.*]], i64 [[N:%.*]]) {
|
|
; CHECK-NEXT: [[ENTRY:.*]]:
|
|
; CHECK-NEXT: br label %[[FOR_BODY:.*]]
|
|
; CHECK: [[FOR_BODY]]:
|
|
; CHECK-NEXT: [[INDVARS_IV:%.*]] = phi i64 [ 0, %[[ENTRY]] ], [ [[INDVARS_IV_NEXT:%.*]], %[[FOR_BODY]] ]
|
|
; CHECK-NEXT: [[MAX_09:%.*]] = phi i64 [ [[MM]], %[[ENTRY]] ], [ [[SPEC_SELECT:%.*]], %[[FOR_BODY]] ]
|
|
; CHECK-NEXT: [[IDX_011:%.*]] = phi i64 [ [[II]], %[[ENTRY]] ], [ [[SPEC_SELECT7:%.*]], %[[FOR_BODY]] ]
|
|
; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds i64, ptr [[A]], i64 [[INDVARS_IV]]
|
|
; CHECK-NEXT: [[TMP0:%.*]] = load i64, ptr [[ARRAYIDX]], align 4
|
|
; CHECK-NEXT: [[CMP1:%.*]] = icmp slt i64 [[MAX_09]], [[TMP0]]
|
|
; CHECK-NEXT: [[SPEC_SELECT]] = select i1 [[CMP1]], i64 [[TMP0]], i64 [[MAX_09]]
|
|
; CHECK-NEXT: [[SPEC_SELECT7]] = select i1 [[CMP1]], i64 [[INDVARS_IV]], i64 [[IDX_011]]
|
|
; CHECK-NEXT: [[INDVARS_IV_NEXT]] = add nuw nsw i64 [[INDVARS_IV]], 1
|
|
; CHECK-NEXT: [[EXITCOND_NOT:%.*]] = icmp eq i64 [[INDVARS_IV_NEXT]], [[N]]
|
|
; CHECK-NEXT: br i1 [[EXITCOND_NOT]], label %[[EXIT:.*]], label %[[FOR_BODY]]
|
|
; CHECK: [[EXIT]]:
|
|
; CHECK-NEXT: [[SPEC_SELECT_LCSSA:%.*]] = phi i64 [ [[SPEC_SELECT]], %[[FOR_BODY]] ]
|
|
; CHECK-NEXT: [[SPEC_SELECT7_LCSSA:%.*]] = phi i64 [ [[SPEC_SELECT7]], %[[FOR_BODY]] ]
|
|
; CHECK-NEXT: store i64 [[SPEC_SELECT_LCSSA]], ptr [[RES_MAX]], align 4
|
|
; CHECK-NEXT: ret i64 [[SPEC_SELECT7_LCSSA]]
|
|
;
|
|
entry:
|
|
br label %for.body
|
|
|
|
for.body:
|
|
%indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ]
|
|
%max.09 = phi i64 [ %mm, %entry ], [ %spec.select, %for.body ]
|
|
%idx.011 = phi i64 [ %ii, %entry ], [ %spec.select7, %for.body ]
|
|
%arrayidx = getelementptr inbounds i64, ptr %a, i64 %indvars.iv
|
|
%0 = load i64, ptr %arrayidx
|
|
%cmp1 = icmp slt i64 %max.09, %0
|
|
%spec.select = select i1 %cmp1, i64 %0, i64 %max.09
|
|
%spec.select7 = select i1 %cmp1, i64 %indvars.iv, i64 %idx.011
|
|
%indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
|
|
%exitcond.not = icmp eq i64 %indvars.iv.next, %n
|
|
br i1 %exitcond.not, label %exit, label %for.body
|
|
|
|
exit:
|
|
store i64 %spec.select, ptr %res_max
|
|
ret i64 %spec.select7
|
|
}
|
|
|
|
;
|
|
; Check sge case.
|
|
;
|
|
define i64 @smax_idx_inverted_pred(ptr nocapture readonly %a, i64 %mm, i64 %ii, ptr nocapture writeonly %res_max, i64 %n) {
|
|
; CHECK-LABEL: define i64 @smax_idx_inverted_pred(
|
|
; CHECK-SAME: ptr readonly captures(none) [[A:%.*]], i64 [[MM:%.*]], i64 [[II:%.*]], ptr writeonly captures(none) [[RES_MAX:%.*]], i64 [[N:%.*]]) {
|
|
; CHECK-NEXT: [[ENTRY:.*]]:
|
|
; CHECK-NEXT: br label %[[FOR_BODY:.*]]
|
|
; CHECK: [[FOR_BODY]]:
|
|
; CHECK-NEXT: [[INDVARS_IV:%.*]] = phi i64 [ 0, %[[ENTRY]] ], [ [[INDVARS_IV_NEXT:%.*]], %[[FOR_BODY]] ]
|
|
; CHECK-NEXT: [[MAX_09:%.*]] = phi i64 [ [[MM]], %[[ENTRY]] ], [ [[TMP1:%.*]], %[[FOR_BODY]] ]
|
|
; CHECK-NEXT: [[IDX_011:%.*]] = phi i64 [ [[II]], %[[ENTRY]] ], [ [[SPEC_SELECT7:%.*]], %[[FOR_BODY]] ]
|
|
; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds i64, ptr [[A]], i64 [[INDVARS_IV]]
|
|
; CHECK-NEXT: [[TMP0:%.*]] = load i64, ptr [[ARRAYIDX]], align 4
|
|
; CHECK-NEXT: [[TMP1]] = tail call i64 @llvm.smax.i64(i64 [[MAX_09]], i64 [[TMP0]])
|
|
; CHECK-NEXT: [[CMP1:%.*]] = icmp sge i64 [[TMP0]], [[MAX_09]]
|
|
; CHECK-NEXT: [[SPEC_SELECT7]] = select i1 [[CMP1]], i64 [[INDVARS_IV]], i64 [[IDX_011]]
|
|
; CHECK-NEXT: [[INDVARS_IV_NEXT]] = add nuw nsw i64 [[INDVARS_IV]], 1
|
|
; CHECK-NEXT: [[EXITCOND_NOT:%.*]] = icmp eq i64 [[INDVARS_IV_NEXT]], [[N]]
|
|
; CHECK-NEXT: br i1 [[EXITCOND_NOT]], label %[[EXIT:.*]], label %[[FOR_BODY]]
|
|
; CHECK: [[EXIT]]:
|
|
; CHECK-NEXT: [[DOTLCSSA:%.*]] = phi i64 [ [[TMP1]], %[[FOR_BODY]] ]
|
|
; CHECK-NEXT: [[SPEC_SELECT7_LCSSA:%.*]] = phi i64 [ [[SPEC_SELECT7]], %[[FOR_BODY]] ]
|
|
; CHECK-NEXT: store i64 [[DOTLCSSA]], ptr [[RES_MAX]], align 4
|
|
; CHECK-NEXT: ret i64 [[SPEC_SELECT7_LCSSA]]
|
|
;
|
|
entry:
|
|
br label %for.body
|
|
|
|
for.body:
|
|
%indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ]
|
|
%max.09 = phi i64 [ %mm, %entry ], [ %1, %for.body ]
|
|
%idx.011 = phi i64 [ %ii, %entry ], [ %spec.select7, %for.body ]
|
|
%arrayidx = getelementptr inbounds i64, ptr %a, i64 %indvars.iv
|
|
%0 = load i64, ptr %arrayidx
|
|
%1 = tail call i64 @llvm.smax.i64(i64 %max.09, i64 %0)
|
|
%cmp1 = icmp sge i64 %0, %max.09
|
|
%spec.select7 = select i1 %cmp1, i64 %indvars.iv, i64 %idx.011
|
|
%indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
|
|
%exitcond.not = icmp eq i64 %indvars.iv.next, %n
|
|
br i1 %exitcond.not, label %exit, label %for.body
|
|
|
|
exit:
|
|
store i64 %1, ptr %res_max
|
|
ret i64 %spec.select7
|
|
}
|
|
|
|
;
|
|
; In such cases, the last index should be extracted.
|
|
;
|
|
define i64 @smax_idx_extract_last(ptr nocapture readonly %a, i64 %mm, i64 %ii, ptr nocapture writeonly %res_max, i64 %n) {
|
|
; CHECK-LABEL: define i64 @smax_idx_extract_last(
|
|
; CHECK-SAME: ptr readonly captures(none) [[A:%.*]], i64 [[MM:%.*]], i64 [[II:%.*]], ptr writeonly captures(none) [[RES_MAX:%.*]], i64 [[N:%.*]]) {
|
|
; CHECK-NEXT: [[ENTRY:.*]]:
|
|
; CHECK-NEXT: br label %[[FOR_BODY:.*]]
|
|
; CHECK: [[FOR_BODY]]:
|
|
; CHECK-NEXT: [[INDVARS_IV:%.*]] = phi i64 [ 0, %[[ENTRY]] ], [ [[INDVARS_IV_NEXT:%.*]], %[[FOR_BODY]] ]
|
|
; CHECK-NEXT: [[MAX_09:%.*]] = phi i64 [ [[MM]], %[[ENTRY]] ], [ [[TMP1:%.*]], %[[FOR_BODY]] ]
|
|
; CHECK-NEXT: [[IDX_011:%.*]] = phi i64 [ [[II]], %[[ENTRY]] ], [ [[SPEC_SELECT7:%.*]], %[[FOR_BODY]] ]
|
|
; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds i64, ptr [[A]], i64 [[INDVARS_IV]]
|
|
; CHECK-NEXT: [[TMP0:%.*]] = load i64, ptr [[ARRAYIDX]], align 4
|
|
; CHECK-NEXT: [[TMP1]] = tail call i64 @llvm.smax.i64(i64 [[MAX_09]], i64 [[TMP0]])
|
|
; CHECK-NEXT: [[CMP1_NOT:%.*]] = icmp sgt i64 [[MAX_09]], [[TMP0]]
|
|
; CHECK-NEXT: [[SPEC_SELECT7]] = select i1 [[CMP1_NOT]], i64 [[IDX_011]], i64 [[INDVARS_IV]]
|
|
; CHECK-NEXT: [[INDVARS_IV_NEXT]] = add nuw nsw i64 [[INDVARS_IV]], 1
|
|
; CHECK-NEXT: [[EXITCOND_NOT:%.*]] = icmp eq i64 [[INDVARS_IV_NEXT]], [[N]]
|
|
; CHECK-NEXT: br i1 [[EXITCOND_NOT]], label %[[EXIT:.*]], label %[[FOR_BODY]]
|
|
; CHECK: [[EXIT]]:
|
|
; CHECK-NEXT: [[DOTLCSSA:%.*]] = phi i64 [ [[TMP1]], %[[FOR_BODY]] ]
|
|
; CHECK-NEXT: [[SPEC_SELECT7_LCSSA:%.*]] = phi i64 [ [[SPEC_SELECT7]], %[[FOR_BODY]] ]
|
|
; CHECK-NEXT: store i64 [[DOTLCSSA]], ptr [[RES_MAX]], align 4
|
|
; CHECK-NEXT: ret i64 [[SPEC_SELECT7_LCSSA]]
|
|
;
|
|
entry:
|
|
br label %for.body
|
|
|
|
for.body:
|
|
%indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ]
|
|
%max.09 = phi i64 [ %mm, %entry ], [ %1, %for.body ]
|
|
%idx.011 = phi i64 [ %ii, %entry ], [ %spec.select7, %for.body ]
|
|
%arrayidx = getelementptr inbounds i64, ptr %a, i64 %indvars.iv
|
|
%0 = load i64, ptr %arrayidx
|
|
%1 = tail call i64 @llvm.smax.i64(i64 %max.09, i64 %0)
|
|
%cmp1.not = icmp sgt i64 %max.09, %0
|
|
%spec.select7 = select i1 %cmp1.not, i64 %idx.011, i64 %indvars.iv
|
|
%indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
|
|
%exitcond.not = icmp eq i64 %indvars.iv.next, %n
|
|
br i1 %exitcond.not, label %exit, label %for.body
|
|
|
|
exit:
|
|
store i64 %1, ptr %res_max
|
|
ret i64 %spec.select7
|
|
}
|
|
|
|
;
|
|
; The operands of smax intrinsic and icmp are not the same to be recognized as MMI.
|
|
;
|
|
define i64 @smax_idx_not_vec_1(ptr nocapture readonly %a, ptr nocapture readonly %b, i64 %mm, i64 %ii, ptr nocapture writeonly %res_max, i64 %n) {
|
|
; CHECK-LABEL: define i64 @smax_idx_not_vec_1(
|
|
; CHECK-SAME: ptr readonly captures(none) [[A:%.*]], ptr readonly captures(none) [[B:%.*]], i64 [[MM:%.*]], i64 [[II:%.*]], ptr writeonly captures(none) [[RES_MAX:%.*]], i64 [[N:%.*]]) {
|
|
; CHECK-NEXT: [[ENTRY:.*]]:
|
|
; CHECK-NEXT: br label %[[FOR_BODY:.*]]
|
|
; CHECK: [[FOR_BODY]]:
|
|
; CHECK-NEXT: [[INDVARS_IV:%.*]] = phi i64 [ 0, %[[ENTRY]] ], [ [[INDVARS_IV_NEXT:%.*]], %[[FOR_BODY]] ]
|
|
; CHECK-NEXT: [[MAX_09:%.*]] = phi i64 [ [[MM]], %[[ENTRY]] ], [ [[TMP2:%.*]], %[[FOR_BODY]] ]
|
|
; CHECK-NEXT: [[IDX_011:%.*]] = phi i64 [ [[II]], %[[ENTRY]] ], [ [[SPEC_SELECT7:%.*]], %[[FOR_BODY]] ]
|
|
; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds i64, ptr [[A]], i64 [[INDVARS_IV]]
|
|
; CHECK-NEXT: [[TMP0:%.*]] = load i64, ptr [[ARRAYIDX]], align 4
|
|
; CHECK-NEXT: [[ARRAYIDX_01:%.*]] = getelementptr inbounds i64, ptr [[B]], i64 [[INDVARS_IV]]
|
|
; CHECK-NEXT: [[TMP1:%.*]] = load i64, ptr [[ARRAYIDX]], align 4
|
|
; CHECK-NEXT: [[TMP2]] = tail call i64 @llvm.smax.i64(i64 [[MAX_09]], i64 [[TMP0]])
|
|
; CHECK-NEXT: [[CMP1:%.*]] = icmp slt i64 [[MAX_09]], [[TMP1]]
|
|
; CHECK-NEXT: [[SPEC_SELECT7]] = select i1 [[CMP1]], i64 [[INDVARS_IV]], i64 [[IDX_011]]
|
|
; CHECK-NEXT: [[INDVARS_IV_NEXT]] = add nuw nsw i64 [[INDVARS_IV]], 1
|
|
; CHECK-NEXT: [[EXITCOND_NOT:%.*]] = icmp eq i64 [[INDVARS_IV_NEXT]], [[N]]
|
|
; CHECK-NEXT: br i1 [[EXITCOND_NOT]], label %[[EXIT:.*]], label %[[FOR_BODY]]
|
|
; CHECK: [[EXIT]]:
|
|
; CHECK-NEXT: [[DOTLCSSA:%.*]] = phi i64 [ [[TMP2]], %[[FOR_BODY]] ]
|
|
; CHECK-NEXT: [[SPEC_SELECT7_LCSSA:%.*]] = phi i64 [ [[SPEC_SELECT7]], %[[FOR_BODY]] ]
|
|
; CHECK-NEXT: store i64 [[DOTLCSSA]], ptr [[RES_MAX]], align 4
|
|
; CHECK-NEXT: ret i64 [[SPEC_SELECT7_LCSSA]]
|
|
;
|
|
entry:
|
|
br label %for.body
|
|
|
|
for.body:
|
|
%indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ]
|
|
%max.09 = phi i64 [ %mm, %entry ], [ %2, %for.body ]
|
|
%idx.011 = phi i64 [ %ii, %entry ], [ %spec.select7, %for.body ]
|
|
%arrayidx = getelementptr inbounds i64, ptr %a, i64 %indvars.iv
|
|
%0 = load i64, ptr %arrayidx
|
|
%arrayidx.01 = getelementptr inbounds i64, ptr %b, i64 %indvars.iv
|
|
%1 = load i64, ptr %arrayidx
|
|
%2 = tail call i64 @llvm.smax.i64(i64 %max.09, i64 %0)
|
|
%cmp1 = icmp slt i64 %max.09, %1
|
|
%spec.select7 = select i1 %cmp1, i64 %indvars.iv, i64 %idx.011
|
|
%indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
|
|
%exitcond.not = icmp eq i64 %indvars.iv.next, %n
|
|
br i1 %exitcond.not, label %exit, label %for.body
|
|
|
|
exit:
|
|
store i64 %2, ptr %res_max
|
|
ret i64 %spec.select7
|
|
}
|
|
|
|
;
|
|
; It cannot be recognized as MMI when the operand of index select is not an induction variable.
|
|
;
|
|
define i64 @smax_idx_not_vec_2(ptr nocapture readonly %a, i64 %mm, i64 %ii, ptr nocapture writeonly %res_max, i64 %n) {
|
|
; CHECK-LABEL: define i64 @smax_idx_not_vec_2(
|
|
; CHECK-SAME: ptr readonly captures(none) [[A:%.*]], i64 [[MM:%.*]], i64 [[II:%.*]], ptr writeonly captures(none) [[RES_MAX:%.*]], i64 [[N:%.*]]) {
|
|
; CHECK-NEXT: [[ENTRY:.*]]:
|
|
; CHECK-NEXT: br label %[[FOR_BODY:.*]]
|
|
; CHECK: [[FOR_BODY]]:
|
|
; CHECK-NEXT: [[INDVARS_IV:%.*]] = phi i64 [ 0, %[[ENTRY]] ], [ [[INDVARS_IV_NEXT:%.*]], %[[FOR_BODY]] ]
|
|
; CHECK-NEXT: [[MAX_09:%.*]] = phi i64 [ [[MM]], %[[ENTRY]] ], [ [[TMP1:%.*]], %[[FOR_BODY]] ]
|
|
; CHECK-NEXT: [[IDX_011:%.*]] = phi i64 [ [[II]], %[[ENTRY]] ], [ [[SPEC_SELECT7:%.*]], %[[FOR_BODY]] ]
|
|
; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds i64, ptr [[A]], i64 [[INDVARS_IV]]
|
|
; CHECK-NEXT: [[TMP0:%.*]] = load i64, ptr [[ARRAYIDX]], align 4
|
|
; CHECK-NEXT: [[TMP1]] = tail call i64 @llvm.smax.i64(i64 [[MAX_09]], i64 [[TMP0]])
|
|
; CHECK-NEXT: [[CMP1:%.*]] = icmp slt i64 [[MAX_09]], [[TMP0]]
|
|
; CHECK-NEXT: [[SPEC_SELECT7]] = select i1 [[CMP1]], i64 123, i64 [[IDX_011]]
|
|
; CHECK-NEXT: [[INDVARS_IV_NEXT]] = add nuw nsw i64 [[INDVARS_IV]], 1
|
|
; CHECK-NEXT: [[EXITCOND_NOT:%.*]] = icmp eq i64 [[INDVARS_IV_NEXT]], [[N]]
|
|
; CHECK-NEXT: br i1 [[EXITCOND_NOT]], label %[[EXIT:.*]], label %[[FOR_BODY]]
|
|
; CHECK: [[EXIT]]:
|
|
; CHECK-NEXT: [[DOTLCSSA:%.*]] = phi i64 [ [[TMP1]], %[[FOR_BODY]] ]
|
|
; CHECK-NEXT: [[SPEC_SELECT7_LCSSA:%.*]] = phi i64 [ [[SPEC_SELECT7]], %[[FOR_BODY]] ]
|
|
; CHECK-NEXT: store i64 [[DOTLCSSA]], ptr [[RES_MAX]], align 4
|
|
; CHECK-NEXT: ret i64 [[SPEC_SELECT7_LCSSA]]
|
|
;
|
|
entry:
|
|
br label %for.body
|
|
|
|
for.body:
|
|
%indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ]
|
|
%max.09 = phi i64 [ %mm, %entry ], [ %1, %for.body ]
|
|
%idx.011 = phi i64 [ %ii, %entry ], [ %spec.select7, %for.body ]
|
|
%arrayidx = getelementptr inbounds i64, ptr %a, i64 %indvars.iv
|
|
%0 = load i64, ptr %arrayidx
|
|
%1 = tail call i64 @llvm.smax.i64(i64 %max.09, i64 %0)
|
|
%cmp1 = icmp slt i64 %max.09, %0
|
|
%spec.select7 = select i1 %cmp1, i64 123, i64 %idx.011
|
|
%indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
|
|
%exitcond.not = icmp eq i64 %indvars.iv.next, %n
|
|
br i1 %exitcond.not, label %exit, label %for.body
|
|
|
|
exit:
|
|
store i64 %1, ptr %res_max
|
|
ret i64 %spec.select7
|
|
}
|
|
|
|
declare i64 @llvm.smax.i64(i64, i64)
|