From 753c18f5c00bf64de66b584a252933961bc99df5 Mon Sep 17 00:00:00 2001 From: James Molloy Date: Thu, 8 Sep 2016 12:58:12 +0000 Subject: [PATCH] [Thumb1] AND with a constant operand can be converted into BIC So model the cost of materializing the constant operand C as the minimum of C and ~C. llvm-svn: 280929 --- llvm/lib/Target/ARM/ARMTargetTransformInfo.cpp | 4 ++++ llvm/test/CodeGen/ARM/immcost.ll | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/llvm/lib/Target/ARM/ARMTargetTransformInfo.cpp b/llvm/lib/Target/ARM/ARMTargetTransformInfo.cpp index 2d44adc..4881933 100644 --- a/llvm/lib/Target/ARM/ARMTargetTransformInfo.cpp +++ b/llvm/lib/Target/ARM/ARMTargetTransformInfo.cpp @@ -69,6 +69,10 @@ int ARMTTIImpl::getIntImmCost(unsigned Opcode, unsigned Idx, const APInt &Imm, Idx == 1) return 0; + if (Opcode == Instruction::And) + // Conversion to BIC is free, and means we can use ~Imm instead. + return std::min(getIntImmCost(Imm, Ty), getIntImmCost(~Imm, Ty)); + return getIntImmCost(Imm, Ty); } diff --git a/llvm/test/CodeGen/ARM/immcost.ll b/llvm/test/CodeGen/ARM/immcost.ll index 0d50bed..bfc1fdd 100644 --- a/llvm/test/CodeGen/ARM/immcost.ll +++ b/llvm/test/CodeGen/ARM/immcost.ll @@ -19,3 +19,21 @@ true: ret: ret void } + +; CHECK: Function: h +; CHECK-NOT: Collect constant i32 -193 from +define void @h(i1 %cond, i32 %p, i32 %q) { +entry: + %a = and i32 %p, 4294967103 + call void @g(i32 %a) + br i1 %cond, label %true, label %ret + +true: + %b = and i32 %q, 4294967103 + call void @g(i32 %b) + br label %ret + +ret: + ret void +} + -- 2.7.4