Skip to content

Commit eac2a27

Browse files
committed
[VPlan] Address review
1 parent 138ed04 commit eac2a27

File tree

4 files changed

+74
-62
lines changed

4 files changed

+74
-62
lines changed

llvm/lib/Transforms/Vectorize/VPlan.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1555,9 +1555,6 @@ class VPWidenIntrinsicRecipe : public VPRecipeWithIRFlags, public VPIRMetadata {
15551555
/// True if the intrinsic may have side-effects.
15561556
bool MayHaveSideEffects;
15571557

1558-
/// True if the intrinsic is safe to speculatively execute.
1559-
bool IsSafeToSpeculativelyExecute;
1560-
15611558
public:
15621559
VPWidenIntrinsicRecipe(CallInst &CI, Intrinsic::ID VectorIntrinsicID,
15631560
ArrayRef<VPValue *> CallArguments, Type *Ty,
@@ -1581,7 +1578,6 @@ class VPWidenIntrinsicRecipe : public VPRecipeWithIRFlags, public VPIRMetadata {
15811578
MayHaveSideEffects = MayWriteToMemory ||
15821579
!Attrs.hasAttribute(Attribute::NoUnwind) ||
15831580
!Attrs.hasAttribute(Attribute::WillReturn);
1584-
IsSafeToSpeculativelyExecute = Attrs.hasAttribute(Attribute::Speculatable);
15851581
}
15861582

15871583
~VPWidenIntrinsicRecipe() override = default;
@@ -1621,11 +1617,6 @@ class VPWidenIntrinsicRecipe : public VPRecipeWithIRFlags, public VPIRMetadata {
16211617
/// Returns true if the intrinsic may have side-effects.
16221618
bool mayHaveSideEffects() const { return MayHaveSideEffects; }
16231619

1624-
/// Returns true if the intrinsic is safe to speculatively execute.
1625-
bool isSafeToSpeculativelyExecute() const {
1626-
return IsSafeToSpeculativelyExecute;
1627-
}
1628-
16291620
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
16301621
/// Print the recipe.
16311622
void print(raw_ostream &O, const Twine &Indent,

llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
#include "llvm/Analysis/InstSimplifyFolder.h"
3131
#include "llvm/Analysis/LoopInfo.h"
3232
#include "llvm/Analysis/ScalarEvolutionPatternMatch.h"
33-
#include "llvm/Analysis/ValueTracking.h"
3433
#include "llvm/Analysis/VectorUtils.h"
3534
#include "llvm/IR/Intrinsics.h"
3635
#include "llvm/IR/MDBuilder.h"
@@ -2103,23 +2102,12 @@ void VPlanTransforms::cse(VPlan &Plan) {
21032102
}
21042103
}
21052104

2106-
static bool isSafeToSpeculativelyExecute(VPRecipeBase *R) {
2107-
if (auto *WC = dyn_cast<VPWidenCallRecipe>(R))
2108-
return WC->getCalledScalarFunction()->isSpeculatable();
2109-
if (auto *WI = dyn_cast<VPWidenIntrinsicRecipe>(R))
2110-
return WI->isSafeToSpeculativelyExecute();
2111-
if (auto *RepR = dyn_cast<VPReplicateRecipe>(R))
2112-
return isSafeToSpeculativelyExecute(RepR->getUnderlyingInstr());
2113-
return !R->mayHaveSideEffects();
2114-
}
2115-
21162105
/// Move loop-invariant recipes out of the vector loop region in \p Plan.
21172106
static void licm(VPlan &Plan) {
21182107
VPBasicBlock *Preheader = Plan.getVectorPreheader();
21192108

21202109
// Return true if we do not know how to (mechanically) hoist a given recipe
2121-
// out of a loop region. Does not address legality concerns such as aliasing
2122-
// or speculation safety.
2110+
// out of a loop region.
21232111
auto CannotHoistRecipe = [](VPRecipeBase &R) {
21242112
// TODO: Relax checks in the future, e.g. we could also hoist reads, if
21252113
// their memory location is not modified in the vector loop.
@@ -2133,16 +2121,16 @@ static void licm(VPlan &Plan) {
21332121

21342122
// Hoist any loop invariant recipes from the vector loop region to the
21352123
// preheader. Preform a shallow traversal of the vector loop region, to
2136-
// exclude recipes in replicate regions.
2124+
// exclude recipes in replicate regions. Since the vector loop region is
2125+
// guaranteed to execute, if the vector pre-header is, we don't need to check
2126+
// speculation safety.
21372127
VPRegionBlock *LoopRegion = Plan.getVectorLoopRegion();
2138-
bool GuaranteedToExecute = Preheader->getSingleSuccessor() == LoopRegion;
21392128
for (VPBasicBlock *VPBB : VPBlockUtils::blocksOnly<VPBasicBlock>(
21402129
vp_depth_first_shallow(LoopRegion->getEntry()))) {
21412130
for (VPRecipeBase &R : make_early_inc_range(*VPBB)) {
21422131
if (CannotHoistRecipe(R))
21432132
continue;
2144-
if ((!GuaranteedToExecute && !isSafeToSpeculativelyExecute(&R)) ||
2145-
any_of(R.operands(), [](VPValue *Op) {
2133+
if (any_of(R.operands(), [](VPValue *Op) {
21462134
return !Op->isDefinedOutsideLoopRegions();
21472135
}))
21482136
continue;

llvm/test/Transforms/LoopVectorize/X86/funclet.ll

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,11 @@
1-
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 6
21
; RUN: opt -S -passes=loop-vectorize < %s | FileCheck %s
32
target datalayout = "e-m:x-p:32:32-i64:64-f80:32-n8:16:32-a:0:32-S32"
43
target triple = "i686-pc-windows-msvc18.0.0"
54

65
define void @test1() #0 personality ptr @__CxxFrameHandler3 {
7-
; CHECK-LABEL: define void @test1(
8-
; CHECK-SAME: ) #[[ATTR0:[0-9]+]] personality ptr @__CxxFrameHandler3 {
9-
; CHECK-NEXT: [[ENTRY:.*:]]
10-
; CHECK-NEXT: invoke void @_CxxThrowException(ptr null, ptr null)
11-
; CHECK-NEXT: to label %[[UNREACHABLE:.*]] unwind label %[[CATCH_DISPATCH:.*]]
12-
; CHECK: [[CATCH_DISPATCH]]:
13-
; CHECK-NEXT: [[TMP0:%.*]] = catchswitch within none [label %catch] unwind to caller
14-
; CHECK: [[CATCH:.*]]:
15-
; CHECK-NEXT: [[TMP1:%.*]] = catchpad within [[TMP0]] [ptr null, i32 64, ptr null]
16-
; CHECK-NEXT: br label %[[FOR_BODY:.*]]
17-
; CHECK: [[FOR_COND_CLEANUP:.*]]:
18-
; CHECK-NEXT: catchret from [[TMP1]] to label %[[TRY_CONT:.*]]
19-
; CHECK: [[FOR_BODY]]:
20-
; CHECK-NEXT: [[I_07:%.*]] = phi i32 [ 0, %[[CATCH]] ], [ [[INC:%.*]], %[[FOR_BODY]] ]
21-
; CHECK-NEXT: [[CALL:%.*]] = call double @floor(double 1.000000e+00) #[[ATTR1:[0-9]+]] [ "funclet"(token [[TMP1]]) ]
22-
; CHECK-NEXT: [[INC]] = add nuw nsw i32 [[I_07]], 1
23-
; CHECK-NEXT: [[EXITCOND:%.*]] = icmp eq i32 [[INC]], 1024
24-
; CHECK-NEXT: br i1 [[EXITCOND]], label %[[FOR_COND_CLEANUP]], label %[[FOR_BODY]]
25-
; CHECK: [[TRY_CONT]]:
26-
; CHECK-NEXT: ret void
27-
; CHECK: [[UNREACHABLE]]:
28-
; CHECK-NEXT: unreachable
29-
;
306
entry:
317
invoke void @_CxxThrowException(ptr null, ptr null)
32-
to label %unreachable unwind label %catch.dispatch
8+
to label %unreachable unwind label %catch.dispatch
339

3410
catch.dispatch: ; preds = %entry
3511
%0 = catchswitch within none [label %catch] unwind to caller
@@ -43,7 +19,8 @@ for.cond.cleanup: ; preds = %for.body
4319

4420
for.body: ; preds = %for.body, %catch
4521
%i.07 = phi i32 [ 0, %catch ], [ %inc, %for.body ]
46-
%call = call double @floor(double 1.0) #1 [ "funclet"(token %1) ]
22+
%tofp = uitofp i32 %i.07 to double
23+
%call = call double @floor(double %tofp) #1 [ "funclet"(token %1) ]
4724
%inc = add nuw nsw i32 %i.07, 1
4825
%exitcond = icmp eq i32 %inc, 1024
4926
br i1 %exitcond, label %for.cond.cleanup, label %for.body
@@ -55,6 +32,9 @@ unreachable: ; preds = %entry
5532
unreachable
5633
}
5734

35+
; CHECK-LABEL: define void @test1(
36+
; CHECK: %[[cpad:.*]] = catchpad within {{.*}} [ptr null, i32 64, ptr null]
37+
; CHECK: call <16 x double> @llvm.floor.v16f64(<16 x double> {{.*}}) [ "funclet"(token %[[cpad]]) ]
5838

5939
declare x86_stdcallcc void @_CxxThrowException(ptr, ptr)
6040

llvm/test/Transforms/LoopVectorize/assume.ll

Lines changed: 63 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,9 @@ define void @test1(ptr noalias nocapture %a, ptr noalias nocapture readonly %b)
3434
; CHECK-NEXT: [[TMP12:%.*]] = icmp eq i64 [[INDEX_NEXT]], 1600
3535
; CHECK-NEXT: br i1 [[TMP12]], label %[[MIDDLE_BLOCK:.*]], label %[[VECTOR_BODY]], !llvm.loop [[LOOP0:![0-9]+]]
3636
; CHECK: [[MIDDLE_BLOCK]]:
37-
; CHECK-NEXT: br [[FOR_END:label %.*]]
38-
; CHECK: [[SCALAR_PH:.*:]]
37+
; CHECK-NEXT: br label %[[FOR_END:.*]]
38+
; CHECK: [[FOR_END]]:
39+
; CHECK-NEXT: ret void
3940
;
4041
entry:
4142
br label %for.body
@@ -57,10 +58,6 @@ for.end: ; preds = %for.body
5758
ret void
5859
}
5960

60-
declare void @llvm.assume(i1) #0
61-
62-
attributes #0 = { nounwind willreturn }
63-
6461
define void @test2(ptr noalias %a, ptr noalias %b) {
6562
; CHECK-LABEL: define void @test2(
6663
; CHECK-SAME: ptr noalias [[A:%.*]], ptr noalias [[B:%.*]]) {
@@ -92,10 +89,11 @@ define void @test2(ptr noalias %a, ptr noalias %b) {
9289
; CHECK-NEXT: store <2 x float> [[TMP6]], ptr [[TMP8]], align 4
9390
; CHECK-NEXT: [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 4
9491
; CHECK-NEXT: [[TMP9:%.*]] = icmp eq i64 [[INDEX_NEXT]], 1600
95-
; CHECK-NEXT: br i1 [[TMP9]], label %[[MIDDLE_BLOCK:.*]], label %[[VECTOR_BODY]], !llvm.loop [[LOOP4:![0-9]+]]
92+
; CHECK-NEXT: br i1 [[TMP9]], label %[[MIDDLE_BLOCK:.*]], label %[[VECTOR_BODY]], !llvm.loop [[LOOP3:![0-9]+]]
9693
; CHECK: [[MIDDLE_BLOCK]]:
97-
; CHECK-NEXT: br [[FOR_END:label %.*]]
98-
; CHECK: [[SCALAR_PH:.*:]]
94+
; CHECK-NEXT: br label %[[FOR_END:.*]]
95+
; CHECK: [[FOR_END]]:
96+
; CHECK-NEXT: ret void
9997
;
10098
entry:
10199
%ptrint = ptrtoint ptr %a to i64
@@ -163,7 +161,7 @@ define void @predicated_assume(ptr noalias nocapture readonly %a, ptr noalias no
163161
; CHECK-NEXT: [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 4
164162
; CHECK-NEXT: [[VEC_IND_NEXT]] = add <2 x i64> [[STEP_ADD]], splat (i64 2)
165163
; CHECK-NEXT: [[TMP9:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]]
166-
; CHECK-NEXT: br i1 [[TMP9]], label %[[MIDDLE_BLOCK:.*]], label %[[VECTOR_BODY]], !llvm.loop [[LOOP6:![0-9]+]]
164+
; CHECK-NEXT: br i1 [[TMP9]], label %[[MIDDLE_BLOCK:.*]], label %[[VECTOR_BODY]], !llvm.loop [[LOOP4:![0-9]+]]
167165
; CHECK: [[MIDDLE_BLOCK]]:
168166
; CHECK-NEXT: [[CMP_N:%.*]] = icmp eq i64 [[TMP0]], [[N_VEC]]
169167
; CHECK-NEXT: br i1 [[CMP_N]], [[FOR_COND_CLEANUP_LOOPEXIT:label %.*]], label %[[SCALAR_PH]]
@@ -204,3 +202,58 @@ if.end5: ; preds = %for.body, %if.else
204202
%cmp = icmp eq i64 %indvars.iv.next, %0
205203
br i1 %cmp, label %for.cond.cleanup.loopexit, label %for.body
206204
}
205+
206+
define void @operand_bundle(ptr noalias %a, ptr noalias %b) {
207+
; CHECK-LABEL: define void @operand_bundle(
208+
; CHECK-SAME: ptr noalias [[A:%.*]], ptr noalias [[B:%.*]]) {
209+
; CHECK-NEXT: [[ENTRY:.*:]]
210+
; CHECK-NEXT: br label %[[VECTOR_PH:.*]]
211+
; CHECK: [[VECTOR_PH]]:
212+
; CHECK-NEXT: br label %[[VECTOR_BODY:.*]]
213+
; CHECK: [[VECTOR_BODY]]:
214+
; CHECK-NEXT: [[INDEX:%.*]] = phi i64 [ 0, %[[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], %[[VECTOR_BODY]] ]
215+
; CHECK-NEXT: [[TMP0:%.*]] = add i64 [[INDEX]], 0
216+
; CHECK-NEXT: [[TMP1:%.*]] = add i64 [[INDEX]], 1
217+
; CHECK-NEXT: [[TMP2:%.*]] = add i64 [[INDEX]], 2
218+
; CHECK-NEXT: [[TMP3:%.*]] = add i64 [[INDEX]], 3
219+
; CHECK-NEXT: [[TMP4:%.*]] = getelementptr inbounds float, ptr [[B]], i64 [[TMP0]]
220+
; CHECK-NEXT: [[TMP5:%.*]] = getelementptr inbounds float, ptr [[TMP4]], i32 2
221+
; CHECK-NEXT: [[WIDE_LOAD:%.*]] = load <2 x float>, ptr [[TMP4]], align 4
222+
; CHECK-NEXT: [[WIDE_LOAD1:%.*]] = load <2 x float>, ptr [[TMP5]], align 4
223+
; CHECK-NEXT: tail call void @llvm.assume(i1 true) [ "align"(ptr [[A]], i64 [[TMP0]]) ]
224+
; CHECK-NEXT: tail call void @llvm.assume(i1 true) [ "align"(ptr [[A]], i64 [[TMP1]]) ]
225+
; CHECK-NEXT: tail call void @llvm.assume(i1 true) [ "align"(ptr [[A]], i64 [[TMP2]]) ]
226+
; CHECK-NEXT: tail call void @llvm.assume(i1 true) [ "align"(ptr [[A]], i64 [[TMP3]]) ]
227+
; CHECK-NEXT: [[TMP6:%.*]] = fadd <2 x float> [[WIDE_LOAD]], splat (float 1.000000e+00)
228+
; CHECK-NEXT: [[TMP7:%.*]] = fadd <2 x float> [[WIDE_LOAD1]], splat (float 1.000000e+00)
229+
; CHECK-NEXT: [[TMP8:%.*]] = getelementptr inbounds float, ptr [[A]], i64 [[TMP0]]
230+
; CHECK-NEXT: [[TMP9:%.*]] = getelementptr inbounds float, ptr [[TMP8]], i32 2
231+
; CHECK-NEXT: store <2 x float> [[TMP6]], ptr [[TMP8]], align 4
232+
; CHECK-NEXT: store <2 x float> [[TMP7]], ptr [[TMP9]], align 4
233+
; CHECK-NEXT: [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 4
234+
; CHECK-NEXT: [[TMP10:%.*]] = icmp eq i64 [[INDEX_NEXT]], 1600
235+
; CHECK-NEXT: br i1 [[TMP10]], label %[[MIDDLE_BLOCK:.*]], label %[[VECTOR_BODY]], !llvm.loop [[LOOP6:![0-9]+]]
236+
; CHECK: [[MIDDLE_BLOCK]]:
237+
; CHECK-NEXT: br label %[[FOR_END:.*]]
238+
; CHECK: [[FOR_END]]:
239+
; CHECK-NEXT: ret void
240+
;
241+
entry:
242+
br label %for.body
243+
244+
for.body: ; preds = %for.body, %entry
245+
%iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]
246+
%arrayidx = getelementptr inbounds float, ptr %b, i64 %iv
247+
%0 = load float, ptr %arrayidx, align 4
248+
%cmp1 = fcmp ogt float %0, 1.000000e+02
249+
tail call void @llvm.assume(i1 true) ["align"(ptr %a, i64 %iv)]
250+
%add = fadd float %0, 1.000000e+00
251+
%arrayidx5 = getelementptr inbounds float, ptr %a, i64 %iv
252+
store float %add, ptr %arrayidx5, align 4
253+
%iv.next = add nuw nsw i64 %iv, 1
254+
%exitcond = icmp eq i64 %iv, 1599
255+
br i1 %exitcond, label %for.end, label %for.body
256+
257+
for.end: ; preds = %for.body
258+
ret void
259+
}

0 commit comments

Comments
 (0)