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(CmpOp0) && CmpOp0->hasOneUse()) || - (isa(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()) || 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