From: Guozhi Wei Date: Thu, 14 Sep 2017 19:20:02 +0000 (+0000) Subject: [TargetTransformInfo] Detect 0 latency instructions X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=5cf5798b90e622f8b2db6b9e166bc404082c2c0e;p=llvm [TargetTransformInfo] Detect 0 latency instructions For instructions that unlikely generate machine instructions, they should also have 0 latency. Differential Revision: https://reviews.llvm.org/D37833 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@313288 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/Analysis/TargetTransformInfoImpl.h b/include/llvm/Analysis/TargetTransformInfoImpl.h index 87d30ef225e..2191bd16456 100644 --- a/include/llvm/Analysis/TargetTransformInfoImpl.h +++ b/include/llvm/Analysis/TargetTransformInfoImpl.h @@ -775,7 +775,9 @@ public: } int getInstructionLatency(const Instruction *I) { - if (isa(I)) + SmallVector Operands(I->value_op_begin(), + I->value_op_end()); + if (getUserCost(I, Operands) == TTI::TCC_Free) return 0; if (isa(I)) diff --git a/test/Analysis/CostModel/X86/costmodel.ll b/test/Analysis/CostModel/X86/costmodel.ll index 1b3d784323b..f7958580b13 100644 --- a/test/Analysis/CostModel/X86/costmodel.ll +++ b/test/Analysis/CostModel/X86/costmodel.ll @@ -3,6 +3,8 @@ ; Tests if the interface TargetTransformInfo::getInstructionCost() works correctly. +target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128" + define i64 @foo(i64 %arg) { ; LATENCY: cost of 1 {{.*}} %I64 = add @@ -13,6 +15,22 @@ define i64 @foo(i64 %arg) { ; CODESIZE: cost of 1 {{.*}} load load i64, i64* undef, align 4 + ; LATENCY: cost of 0 {{.*}} bitcast + ; CODESIZE: cost of 0 {{.*}} bitcast + %BC = bitcast i8* undef to i32* + + ; LATENCY: cost of 0 {{.*}} inttoptr + ; CODESIZE: cost of 0 {{.*}} inttoptr + %I2P = inttoptr i64 undef to i8* + + ; LATENCY: cost of 0 {{.*}} ptrtoint + ; CODESIZE: cost of 0 {{.*}} ptrtoint + %P2I = ptrtoint i8* undef to i64 + + ; LATENCY: cost of 0 {{.*}} trunc + ; CODESIZE: cost of 0 {{.*}} trunc + %TC = trunc i64 undef to i32 + ; LATENCY: cost of 1 {{.*}} ret ; CODESIZE: cost of 1 {{.*}} ret ret i64 undef