[PATCH] D54742: [CodeMetrics] Don't let extends of i1 be free.

Jonas Paulsson via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 3 06:46:10 PST 2018


jonpa updated this revision to Diff 176390.
jonpa added a comment.

Added comment as requested.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D54742/new/

https://reviews.llvm.org/D54742

Files:
  include/llvm/Analysis/TargetTransformInfoImpl.h
  test/Transforms/Inline/SystemZ/ext-i1-cost.ll


Index: test/Transforms/Inline/SystemZ/ext-i1-cost.ll
===================================================================
--- /dev/null
+++ test/Transforms/Inline/SystemZ/ext-i1-cost.ll
@@ -0,0 +1,60 @@
+; REQUIRES: asserts
+; RUN: opt -inline -mtriple=s390x-unknown-linux -mcpu=z13 -S \
+; RUN:   -debug-only=inline-cost < %s 2>&1 | FileCheck %s
+;
+; Check that getUserCost() does not return TCC_Free for extensions of
+; i1. This is tested indirectly by looking at the NumInstructionsSimplified
+; stat from Inliner. Only cost-free instructions increase this counter so the
+; functions below should get a value of 1 for it (for the ret instruction).
+
+define i64 @outer1(i64 %v) {
+  %z = call i64 @inner1(i64 %v)
+  ret i64 %z
+}
+; CHECK: Analyzing call of inner1... (caller:outer1)
+; CHECK: NumInstructionsSimplified: 1
+; CHECK: NumInstructions: 3
+define i64 @inner1(i64 %v) {
+  %cmp = icmp eq i64 %v, 0
+  %z = zext i1 %cmp to i64
+  ret i64 %z
+}
+
+define i64 @outer2(i64 %v) {
+  %z = call i64 @inner2(i64 %v)
+  ret i64 %z
+}
+; CHECK: Analyzing call of inner2... (caller:outer2)
+; CHECK: NumInstructionsSimplified: 1
+; CHECK: NumInstructions: 3
+define i64 @inner2(i64 %v) {
+  %cmp = icmp eq i64 %v, 0
+  %z = sext i1 %cmp to i64
+  ret i64 %z
+}
+
+define double @outer3(i64 %v) {
+  %z = call double @inner3(i64 %v)
+  ret double %z
+}
+; CHECK: Analyzing call of inner3... (caller:outer3)
+; CHECK: NumInstructionsSimplified: 1
+; CHECK: NumInstructions: 3
+define double @inner3(i64 %v) {
+  %cmp = icmp eq i64 %v, 0
+  %z = uitofp i1 %cmp to double
+  ret double %z
+}
+
+define double @outer4(i64 %v) {
+  %z = call double @inner4(i64 %v)
+  ret double %z
+}
+; CHECK: Analyzing call of inner4... (caller:outer4)
+; CHECK: NumInstructionsSimplified: 1
+; CHECK: NumInstructions: 3
+define double @inner4(i64 %v) {
+  %cmp = icmp eq i64 %v, 0
+  %z = sitofp i1 %cmp to double
+  ret double %z
+}
Index: include/llvm/Analysis/TargetTransformInfoImpl.h
===================================================================
--- include/llvm/Analysis/TargetTransformInfoImpl.h
+++ include/llvm/Analysis/TargetTransformInfoImpl.h
@@ -807,15 +807,12 @@
       return static_cast<T *>(this)->getCallCost(F, Arguments);
     }
 
-    if (const CastInst *CI = dyn_cast<CastInst>(U)) {
-      // Result of a cmp instruction is often extended (to be used by other
-      // cmp instructions, logical or return instructions). These are usually
-      // nop on most sane targets.
-      if (isa<CmpInst>(CI->getOperand(0)))
-        return TTI::TCC_Free;
-      if (isa<SExtInst>(CI) || isa<ZExtInst>(CI) || isa<FPExtInst>(CI))
-        return static_cast<T *>(this)->getExtCost(CI, Operands.back());
-    }
+    if (isa<SExtInst>(U) || isa<ZExtInst>(U) || isa<FPExtInst>(U))
+      // The old behaviour of generally treating extensions of i1 to be free
+      // has been removed. A target that needs it should override this
+      // method.
+      return static_cast<T *>(this)->getExtCost(cast<Instruction>(U),
+                                                Operands.back());
 
     return static_cast<T *>(this)->getOperationCost(
         Operator::getOpcode(U), U->getType(),


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D54742.176390.patch
Type: text/x-patch
Size: 3196 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181203/3a51a33a/attachment.bin>


More information about the llvm-commits mailing list