[llvm] b3b9be4 - SpeculativeExecution: Allow speculating more instruction types

Piotr Sobczak via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 18 08:00:43 PST 2020


Author: Piotr Sobczak
Date: 2020-11-18T17:00:19+01:00
New Revision: b3b9be4ae77ed1d6e59253d84184654577aa76e7

URL: https://github.com/llvm/llvm-project/commit/b3b9be4ae77ed1d6e59253d84184654577aa76e7
DIFF: https://github.com/llvm/llvm-project/commit/b3b9be4ae77ed1d6e59253d84184654577aa76e7.diff

LOG: SpeculativeExecution: Allow speculating more instruction types

Support more instructions in SpeculativeExecution pass:
- ExtractValue
- InsertValue
- Trunc
- Freeze

Differential Revision: https://reviews.llvm.org/D91688

Added: 
    llvm/test/Transforms/SpeculativeExecution/spec-other.ll

Modified: 
    llvm/lib/Transforms/Scalar/SpeculativeExecution.cpp
    llvm/test/Transforms/SpeculativeExecution/spec-casts.ll
    llvm/test/Transforms/SpeculativeExecution/spec-fp.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Scalar/SpeculativeExecution.cpp b/llvm/lib/Transforms/Scalar/SpeculativeExecution.cpp
index 9914a889dc95..5baab5684c96 100644
--- a/llvm/lib/Transforms/Scalar/SpeculativeExecution.cpp
+++ b/llvm/lib/Transforms/Scalar/SpeculativeExecution.cpp
@@ -245,9 +245,13 @@ static unsigned ComputeSpeculationCost(const Instruction *I,
     case Instruction::FNeg:
     case Instruction::ICmp:
     case Instruction::FCmp:
+    case Instruction::Trunc:
+    case Instruction::Freeze:
     case Instruction::ExtractElement:
     case Instruction::InsertElement:
     case Instruction::ShuffleVector:
+    case Instruction::ExtractValue:
+    case Instruction::InsertValue:
       return TTI.getUserCost(I, TargetTransformInfo::TCK_SizeAndLatency);
 
     default:

diff  --git a/llvm/test/Transforms/SpeculativeExecution/spec-casts.ll b/llvm/test/Transforms/SpeculativeExecution/spec-casts.ll
index c75d7449d114..223458730800 100644
--- a/llvm/test/Transforms/SpeculativeExecution/spec-casts.ll
+++ b/llvm/test/Transforms/SpeculativeExecution/spec-casts.ll
@@ -134,3 +134,16 @@ a:
 b:
   ret void
 }
+
+; CHECK-LABEL: @ifThen_trunc(
+; CHECK: trunc
+; CHECK: br i1 true
+define void @ifThen_trunc() {
+  br i1 true, label %a, label %b
+a:
+  %x = trunc i32 undef to i16
+  br label %b
+
+b:
+  ret void
+}

diff  --git a/llvm/test/Transforms/SpeculativeExecution/spec-fp.ll b/llvm/test/Transforms/SpeculativeExecution/spec-fp.ll
index 17f942f5fcfe..181ce3757d48 100644
--- a/llvm/test/Transforms/SpeculativeExecution/spec-fp.ll
+++ b/llvm/test/Transforms/SpeculativeExecution/spec-fp.ll
@@ -99,46 +99,3 @@ a:
 b:
   ret void
 }
-
-; CHECK-LABEL: @ifThen_shuffle(
-; CHECK: shufflevector
-; CHECK: br i1 true
-define void @ifThen_shuffle() {
-  br i1 true, label %a, label %b
-
-a:
-  %x = shufflevector <2 x float> undef, <2 x float> undef, <2 x i32> zeroinitializer
-  br label %b
-
-b:
-  ret void
-}
-
-; CHECK-LABEL: @ifThen_extract(
-; CHECK: extractelement
-; CHECK: br i1 true
-define void @ifThen_extract() {
-  br i1 true, label %a, label %b
-
-a:
-  %x = extractelement <2 x float> undef, i32 1
-  br label %b
-
-b:
-  ret void
-}
-
-
-; CHECK-LABEL: @ifThen_insert(
-; CHECK: insertelement
-; CHECK: br i1 true
-define void @ifThen_insert() {
-  br i1 true, label %a, label %b
-
-a:
-  %x = insertelement <2 x float> undef, float undef, i32 1
-  br label %b
-
-b:
-  ret void
-}

diff  --git a/llvm/test/Transforms/SpeculativeExecution/spec-other.ll b/llvm/test/Transforms/SpeculativeExecution/spec-other.ll
new file mode 100644
index 000000000000..43ee9cfb1508
--- /dev/null
+++ b/llvm/test/Transforms/SpeculativeExecution/spec-other.ll
@@ -0,0 +1,88 @@
+; 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_shuffle(
+; CHECK: shufflevector
+; CHECK: br i1 true
+define void @ifThen_shuffle() {
+  br i1 true, label %a, label %b
+
+a:
+  %x = shufflevector <2 x float> undef, <2 x float> undef, <2 x i32> zeroinitializer
+  br label %b
+
+b:
+  ret void
+}
+
+; CHECK-LABEL: @ifThen_extract(
+; CHECK: extractelement
+; CHECK: br i1 true
+define void @ifThen_extract() {
+  br i1 true, label %a, label %b
+
+a:
+  %x = extractelement <2 x float> undef, i32 1
+  br label %b
+
+b:
+  ret void
+}
+
+
+; CHECK-LABEL: @ifThen_insert(
+; CHECK: insertelement
+; CHECK: br i1 true
+define void @ifThen_insert() {
+  br i1 true, label %a, label %b
+
+a:
+  %x = insertelement <2 x float> undef, float undef, i32 1
+  br label %b
+
+b:
+  ret void
+}
+
+; 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
+}
+
+; CHECK-LABEL: @ifThen_freeze(
+; CHECK: freeze
+; CHECK: br i1 true
+define void @ifThen_freeze() {
+  br i1 true, label %a, label %b
+
+a:
+  %x = freeze i32 undef
+  br label %b
+
+b:
+  ret void
+}


        


More information about the llvm-commits mailing list