[llvm] r285438 - SpeculativeExecution: Allow speculating more inst types

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 28 13:00:33 PDT 2016


Author: arsenm
Date: Fri Oct 28 15:00:33 2016
New Revision: 285438

URL: http://llvm.org/viewvc/llvm-project?rev=285438&view=rev
Log:
SpeculativeExecution: Allow speculating more inst types

Partial step towards removing the whitelist and only
using TTI's cost.

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

Modified: llvm/trunk/lib/Transforms/Scalar/SpeculativeExecution.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/SpeculativeExecution.cpp?rev=285438&r1=285437&r2=285438&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/SpeculativeExecution.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/SpeculativeExecution.cpp Fri Oct 28 15:00:33 2016
@@ -224,6 +224,24 @@ static unsigned ComputeSpeculationCost(c
     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:

Added: llvm/trunk/test/Transforms/SpeculativeExecution/spec-calls.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/SpeculativeExecution/spec-calls.ll?rev=285438&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/SpeculativeExecution/spec-calls.ll (added)
+++ llvm/trunk/test/Transforms/SpeculativeExecution/spec-calls.ll Fri Oct 28 15:00:33 2016
@@ -0,0 +1,64 @@
+; RUN: opt < %s -S -speculative-execution \
+; RUN:   -spec-exec-max-speculation-cost 4 -spec-exec-max-not-hoisted 3 \
+; RUN:   | FileCheck %s
+
+declare float @llvm.fabs.f32(float) nounwind readnone
+declare i32 @llvm.ctlz.i32(i32, i1) nounwind readnone
+
+declare float @unknown(float)
+declare float @unknown_readnone(float) nounwind readnone
+
+; CHECK-LABEL: @ifThen_fabs(
+; CHECK: call float @llvm.fabs.f32(
+; CHECK: br i1 true
+define void @ifThen_fabs() {
+  br i1 true, label %a, label %b
+
+a:
+  %x = call float @llvm.fabs.f32(float 1.0)
+  br label %b
+
+b:
+  ret void
+}
+
+; CHECK-LABEL: @ifThen_ctlz(
+; CHECK: call i32 @llvm.ctlz.i32(
+; CHECK: br i1 true
+define void @ifThen_ctlz() {
+  br i1 true, label %a, label %b
+
+a:
+  %x = call i32 @llvm.ctlz.i32(i32 0, i1 true)
+  br label %b
+
+b:
+  ret void
+}
+
+; CHECK-LABEL: @ifThen_call_sideeffects(
+; CHECK: br i1 true
+; CHECK: call float @unknown(
+define void @ifThen_call_sideeffects() {
+  br i1 true, label %a, label %b
+
+a:
+  %x = call float @unknown(float 1.0)
+  br label %b
+
+b:
+  ret void
+}
+
+; CHECK-LABEL: @ifThen_call_readnone(
+; CHECK: br i1 true
+; CHECK: call float @unknown_readnone(
+define void @ifThen_call_readnone() {
+  br i1 true, label %a, label %b
+a:
+  %x = call float @unknown_readnone(float 1.0)
+  br label %b
+
+b:
+  ret void
+}

Added: llvm/trunk/test/Transforms/SpeculativeExecution/spec-casts.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/SpeculativeExecution/spec-casts.ll?rev=285438&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/SpeculativeExecution/spec-casts.ll (added)
+++ llvm/trunk/test/Transforms/SpeculativeExecution/spec-casts.ll Fri Oct 28 15:00:33 2016
@@ -0,0 +1,136 @@
+; 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_bitcast(
+; CHECK: bitcast
+; CHECK: br i1 true
+define void @ifThen_bitcast() {
+  br i1 true, label %a, label %b
+
+a:
+  %x = bitcast i32 undef to float
+  br label %b
+
+b:
+  ret void
+}
+
+; CHECK-LABEL: @ifThen_ptrtoint(
+; CHECK: ptrtoint
+; CHECK: br i1 true
+define void @ifThen_ptrtoint() {
+  br i1 true, label %a, label %b
+
+a:
+  %x = ptrtoint i32* undef to i64
+  br label %b
+
+b:
+  ret void
+}
+
+; CHECK-LABEL: @ifThen_inttoptr(
+; CHECK: inttoptr
+; CHECK: br i1 true
+define void @ifThen_inttoptr() {
+  br i1 true, label %a, label %b
+
+a:
+  %x = inttoptr i64 undef to i32*
+  br label %b
+
+b:
+  ret void
+}
+
+; CHECK-LABEL: @ifThen_addrspacecast(
+; CHECK: addrspacecast
+; CHECK: br i1 true
+define void @ifThen_addrspacecast() {
+  br i1 true, label %a, label %b
+a:
+  %x = addrspacecast i32* undef to i32 addrspace(1)*
+  br label %b
+
+b:
+  ret void
+}
+
+; CHECK-LABEL: @ifThen_fptoui(
+; CHECK: fptoui
+; CHECK: br i1 true
+define void @ifThen_fptoui() {
+  br i1 true, label %a, label %b
+a:
+  %x = fptoui float undef to i32
+  br label %b
+
+b:
+  ret void
+}
+
+; CHECK-LABEL: @ifThen_fptosi(
+; CHECK: fptosi
+; CHECK: br i1 true
+define void @ifThen_fptosi() {
+  br i1 true, label %a, label %b
+a:
+  %x = fptosi float undef to i32
+  br label %b
+
+b:
+  ret void
+}
+
+; CHECK-LABEL: @ifThen_uitofp(
+; CHECK: uitofp
+; CHECK: br i1 true
+define void @ifThen_uitofp() {
+  br i1 true, label %a, label %b
+a:
+  %x = uitofp i32 undef to float
+  br label %b
+
+b:
+  ret void
+}
+
+; CHECK-LABEL: @ifThen_sitofp(
+; CHECK: sitofp
+; CHECK: br i1 true
+define void @ifThen_sitofp() {
+  br i1 true, label %a, label %b
+a:
+  %x = sitofp i32 undef to float
+  br label %b
+
+b:
+  ret void
+}
+
+; CHECK-LABEL: @ifThen_fpext(
+; CHECK: fpext
+; CHECK: br i1 true
+define void @ifThen_fpext() {
+  br i1 true, label %a, label %b
+a:
+  %x = fpext float undef to double
+  br label %b
+
+b:
+  ret void
+}
+
+; CHECK-LABEL: @ifThen_fptrunc(
+; CHECK: fptrunc
+; CHECK: br i1 true
+define void @ifThen_fptrunc() {
+  br i1 true, label %a, label %b
+a:
+  %x = fptrunc double undef to float
+  br label %b
+
+b:
+  ret void
+}

Added: llvm/trunk/test/Transforms/SpeculativeExecution/spec-compares.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/SpeculativeExecution/spec-compares.ll?rev=285438&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/SpeculativeExecution/spec-compares.ll (added)
+++ llvm/trunk/test/Transforms/SpeculativeExecution/spec-compares.ll Fri Oct 28 15:00:33 2016
@@ -0,0 +1,31 @@
+; 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_icmp(
+; CHECK: icmp
+; CHECK: br i1 true
+define void @ifThen_icmp() {
+  br i1 true, label %a, label %b
+
+a:
+  %x = icmp eq i32 undef, undef
+  br label %b
+
+b:
+  ret void
+}
+
+; CHECK-LABEL: @ifThen_fcmp(
+; CHECK: fcmp
+; CHECK: br i1 true
+define void @ifThen_fcmp() {
+  br i1 true, label %a, label %b
+
+a:
+  %x = fcmp oeq float undef, undef
+  br label %b
+
+b:
+  ret void
+}

Added: llvm/trunk/test/Transforms/SpeculativeExecution/spec-fp.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/SpeculativeExecution/spec-fp.ll?rev=285438&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/SpeculativeExecution/spec-fp.ll (added)
+++ llvm/trunk/test/Transforms/SpeculativeExecution/spec-fp.ll Fri Oct 28 15:00:33 2016
@@ -0,0 +1,87 @@
+; 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_fadd(
+; CHECK: fadd
+; CHECK: br i1 true
+define void @ifThen_fadd() {
+  br i1 true, label %a, label %b
+
+a:
+  %x = fadd float undef, undef
+  br label %b
+
+b:
+  ret void
+}
+
+; CHECK-LABEL: @ifThen_fsub(
+; CHECK: fsub
+; CHECK: br i1 true
+define void @ifThen_fsub() {
+  br i1 true, label %a, label %b
+
+a:
+  %x = fsub float undef, undef
+  br label %b
+
+b:
+  ret void
+}
+
+; CHECK-LABEL: @ifThen_fneg(
+; CHECK: fsub float -0.0
+; CHECK: br i1 true
+define void @ifThen_fneg() {
+  br i1 true, label %a, label %b
+
+a:
+  %x = fsub float -0.0, undef
+  br label %b
+
+b:
+  ret void
+}
+
+; CHECK-LABEL: @ifThen_fmul(
+; CHECK: fmul
+; CHECK: br i1 true
+define void @ifThen_fmul() {
+  br i1 true, label %a, label %b
+
+a:
+  %x = fmul float undef, undef
+  br label %b
+
+b:
+  ret void
+}
+
+; CHECK-LABEL: @ifThen_fdiv(
+; CHECK: fdiv
+; CHECK: br i1 true
+define void @ifThen_fdiv() {
+  br i1 true, label %a, label %b
+
+a:
+  %x = fdiv float undef, undef
+  br label %b
+
+b:
+  ret void
+}
+
+; CHECK-LABEL: @ifThen_frem(
+; CHECK: frem
+; CHECK: br i1 true
+define void @ifThen_frem() {
+  br i1 true, label %a, label %b
+
+a:
+  %x = frem float undef, undef
+  br label %b
+
+b:
+  ret void
+}




More information about the llvm-commits mailing list