Skip to content

Commit c65cfaf

Browse files
committed
[VPlan] Address review
1 parent 08b53a6 commit c65cfaf

File tree

3 files changed

+11
-52
lines changed

3 files changed

+11
-52
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

0 commit comments

Comments
 (0)