[PATCH] D16836: [CodeGenPrepare] Don't transform select instructions into branches when both of operands are cheap

Junmo Park via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 2 19:27:51 PST 2016


flyingforyou created this revision.
flyingforyou added reviewers: spatel, jmolloy.
flyingforyou added a subscriber: llvm-commits.

If both operands of the select are expected to fold away in lowering,
the mispredicted branch might be more painful.

There is no regressons and improvements on spec2000/2006. (Cortex-A57, Core i5).

But There are two big improvements in test-suite. (Cortex-A57)
|Benchmark Name|Exe time Opt/Ori|
|MultiSource/Benchmarks/TSVC/Searching-dbl/Searching-dbl|87.18%|
|MultiSource/Benchmarks/TSVC/Searching-flt/Searching-flt|83.82%|

And I didn't see notable regressions in test-suite.




http://reviews.llvm.org/D16836

Files:
  lib/CodeGen/CodeGenPrepare.cpp
  test/CodeGen/AArch64/arm64-select.ll

Index: test/CodeGen/AArch64/arm64-select.ll
===================================================================
--- /dev/null
+++ test/CodeGen/AArch64/arm64-select.ll
@@ -0,0 +1,26 @@
+; RUN: llc -march=arm64 -mcpu=cortex-a57 < %s | FileCheck %s
+; We don't transform below case which has cheap operands of select.
+
+target datalayout = "e-m:e-i64:64-i128:128-n32:64-S128"
+target triple = "aarch64-unknown-linux-gnu"
+
+%class.A = type { i32, i32, i32, i32 }
+
+define i32 @test(%class.A* nocapture readonly %cla, float* nocapture readonly %b, i32 %c) #0 {
+entry:
+; CHECK-LABEL: test:
+; CHECK: csel
+  %call = tail call fast float @_Z6getvalv()
+  %0 = load float, float* %b, align 4, !tbaa !0
+  %cmp = fcmp fast olt float %call, %0
+  %a1 = getelementptr inbounds %class.A, %class.A* %cla, i64 0, i32 1
+  %a2 = getelementptr inbounds %class.A, %class.A* %cla, i64 0, i32 2
+  %cond.in = select i1 %cmp, i32* %a1, i32* %a2
+  %cond = load i32, i32* %cond.in, align 4, !tbaa !0
+  ret i32 %cond
+}
+
+declare float @_Z6getvalv() #0
+
+!0 = !{!1, !1, i64 0}
+!1 = distinct !{!"int", !1, i64 0}
\ No newline at end of file
Index: lib/CodeGen/CodeGenPrepare.cpp
===================================================================
--- lib/CodeGen/CodeGenPrepare.cpp
+++ lib/CodeGen/CodeGenPrepare.cpp
@@ -4475,6 +4475,14 @@
   if (!Cmp || !Cmp->hasOneUse())
     return false;
 
+  // If both operand of the select is expected to fold away in lowering,
+  // the mispredicted branch might be more painful.
+  auto *TI = dyn_cast<Instruction>(SI->getTrueValue());
+  auto *FI = dyn_cast<Instruction>(SI->getFalseValue());
+  if (TI && FI && TTI->getUserCost(TI) == TargetTransformInfo::TCC_Free &&
+      TTI->getUserCost(FI) == TargetTransformInfo::TCC_Free)
+    return false;
+
   Value *CmpOp0 = Cmp->getOperand(0);
   Value *CmpOp1 = Cmp->getOperand(1);
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D16836.46714.patch
Type: text/x-patch
Size: 1862 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160203/f2b5c8d5/attachment.bin>


More information about the llvm-commits mailing list