[PATCH] D16836: [CodeGenPrepare] Remove load-based heuristic

Junmo Park via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 18 17:46:14 PST 2016


flyingforyou retitled this revision from "[CodeGenPrepare] Don't transform select instructions into branches when both of operands are cheap" to "[CodeGenPrepare] Remove load-based heuristic".
flyingforyou updated the summary for this revision.
flyingforyou updated this revision to Diff 48437.
flyingforyou added a comment.

Addressed Sanjay's suggestion.

Thanks.


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,17 +4475,6 @@
   if (!Cmp || !Cmp->hasOneUse())
     return false;
 
-  Value *CmpOp0 = Cmp->getOperand(0);
-  Value *CmpOp1 = Cmp->getOperand(1);
-
-  // Emit "cmov on compare with a memory operand" as a branch to avoid stalls
-  // on a load from memory. But if the load is used more than once, do not
-  // change the select to a branch because the load is probably needed
-  // regardless of whether the branch is taken or not.
-  if ((isa<LoadInst>(CmpOp0) && CmpOp0->hasOneUse()) ||
-      (isa<LoadInst>(CmpOp1) && CmpOp1->hasOneUse()))
-    return true;
-
   // If either operand of the select is expensive and only needed on one side
   // of the select, we should form a branch.
   if (sinkSelectOperand(TTI, SI->getTrueValue()) ||


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


More information about the llvm-commits mailing list