From 7fa7b1a23a3f564c27049e87a8b7caa31035e0a8 Mon Sep 17 00:00:00 2001 From: Chandler Carruth Date: Wed, 10 May 2017 12:30:07 +0000 Subject: [PATCH] Revert r301950: SpeculativeExecution: Stop using whitelist for costs This pass doesn't correctly handle testing for when it is legal to hoist arbitrary instructions. The whitelist happens to make it safe, so before it is removed the pass's legality checks will need to be enhanced. Details have been added to the code review thread for the patch. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@302640 91177308-0d34-0410-b5e6-96231b3b80d8 --- .../Scalar/SpeculativeExecution.cpp | 43 ++++++++++- .../SpeculativeExecution/spec-other.ll | 32 -------- .../SpeculativeExecution/spec-vector.ll | 73 ------------------- 3 files changed, 42 insertions(+), 106 deletions(-) delete mode 100644 test/Transforms/SpeculativeExecution/spec-other.ll delete mode 100644 test/Transforms/SpeculativeExecution/spec-vector.ll diff --git a/lib/Transforms/Scalar/SpeculativeExecution.cpp b/lib/Transforms/Scalar/SpeculativeExecution.cpp index a0fc966cee2..a7c308b5987 100644 --- a/lib/Transforms/Scalar/SpeculativeExecution.cpp +++ b/lib/Transforms/Scalar/SpeculativeExecution.cpp @@ -208,6 +208,47 @@ bool SpeculativeExecutionPass::runOnBasicBlock(BasicBlock &B) { return false; } +static unsigned ComputeSpeculationCost(const Instruction *I, + const TargetTransformInfo &TTI) { + switch (Operator::getOpcode(I)) { + case Instruction::GetElementPtr: + case Instruction::Add: + case Instruction::Mul: + case Instruction::And: + case Instruction::Or: + case Instruction::Select: + case Instruction::Shl: + case Instruction::Sub: + case Instruction::LShr: + case Instruction::AShr: + case Instruction::Xor: + case Instruction::ZExt: + case Instruction::SExt: + case Instruction::Call: + case Instruction::BitCast: + case Instruction::PtrToInt: + case Instruction::IntToPtr: + case Instruction::AddrSpaceCast: + case Instruction::FPToUI: + case Instruction::FPToSI: + case Instruction::UIToFP: + case Instruction::SIToFP: + case Instruction::FPExt: + case Instruction::FPTrunc: + case Instruction::FAdd: + case Instruction::FSub: + case Instruction::FMul: + case Instruction::FDiv: + case Instruction::FRem: + case Instruction::ICmp: + case Instruction::FCmp: + return TTI.getUserCost(I); + + default: + return UINT_MAX; // Disallow anything not whitelisted. + } +} + bool SpeculativeExecutionPass::considerHoistingFromTo( BasicBlock &FromBlock, BasicBlock &ToBlock) { SmallSet NotHoisted; @@ -223,7 +264,7 @@ bool SpeculativeExecutionPass::considerHoistingFromTo( unsigned TotalSpeculationCost = 0; for (auto& I : FromBlock) { - const unsigned Cost = TTI->getUserCost(&I); + const unsigned Cost = ComputeSpeculationCost(&I, *TTI); if (Cost != UINT_MAX && isSafeToSpeculativelyExecute(&I) && AllPrecedingUsesFromBlockHoisted(&I)) { TotalSpeculationCost += Cost; diff --git a/test/Transforms/SpeculativeExecution/spec-other.ll b/test/Transforms/SpeculativeExecution/spec-other.ll deleted file mode 100644 index 65e14b69e9e..00000000000 --- a/test/Transforms/SpeculativeExecution/spec-other.ll +++ /dev/null @@ -1,32 +0,0 @@ -; RUN: opt < %s -S -speculative-execution \ -; RUN: -spec-exec-max-speculation-cost 4 -spec-exec-max-not-hoisted 3 \ -; RUN: | FileCheck %s - -; CHECK-LABEL: @ifThen_extractvalue( -; CHECK: extractvalue -; CHECK: br i1 true -define void @ifThen_extractvalue() { - br i1 true, label %a, label %b - -a: - %x = extractvalue { i32, i32 } undef, 0 - br label %b - -b: - ret void -} - -; CHECK-LABEL: @ifThen_insertvalue( -; CHECK: insertvalue -; CHECK: br i1 true -define void @ifThen_insertvalue() { - br i1 true, label %a, label %b - -a: - %x = insertvalue { i32, i32 } undef, i32 undef, 0 - br label %b - -b: - ret void -} - diff --git a/test/Transforms/SpeculativeExecution/spec-vector.ll b/test/Transforms/SpeculativeExecution/spec-vector.ll deleted file mode 100644 index 9c64f1fb100..00000000000 --- a/test/Transforms/SpeculativeExecution/spec-vector.ll +++ /dev/null @@ -1,73 +0,0 @@ -; RUN: opt < %s -S -speculative-execution \ -; RUN: -spec-exec-max-speculation-cost 4 -spec-exec-max-not-hoisted 3 \ -; RUN: | FileCheck %s - -; CHECK-LABEL: @ifThen_extractelement_constindex( -; CHECK: extractelement -; CHECK: br i1 true -define void @ifThen_extractelement_constindex() { - br i1 true, label %a, label %b - -a: - %x = extractelement <4 x i32> undef, i32 0 - br label %b - -b: - ret void -} - -; CHECK-LABEL: @ifThen_extractelement_varindex( -; CHECK: extractelement -; CHECK: br i1 true -define void @ifThen_extractelement_varindex(i32 %idx) { - br i1 true, label %a, label %b - -a: - %x = extractelement <4 x i32> undef, i32 %idx - br label %b - -b: - ret void -} - -; CHECK-LABEL: @ifThen_insertelement_constindex( -; CHECK: insertelement -; CHECK: br i1 true -define void @ifThen_insertelement_constindex() { - br i1 true, label %a, label %b - -a: - %x = insertelement <4 x i32> undef, i32 undef, i32 0 - br label %b - -b: - ret void -} - -; CHECK-LABEL: @ifThen_insertelement_varindex( -; CHECK: insertelement -; CHECK: br i1 true -define void @ifThen_insertelement_varindex(i32 %idx) { - br i1 true, label %a, label %b - -a: - %x = insertelement <4 x i32> undef, i32 undef, i32 %idx - br label %b - -b: - ret void -} - -; CHECK-LABEL: @ifThen_shufflevector( -; CHECK: shufflevector -; CHECK: br i1 true -define void @ifThen_shufflevector() { - br i1 true, label %a, label %b - -a: - %x = shufflevector <4 x i32> undef, <4 x i32> undef, <4 x i32> undef - br label %b - -b: - ret void -} -- 2.40.0