[llvm] r280929 - [Thumb1] AND with a constant operand can be converted into BIC

James Molloy via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 8 05:58:12 PDT 2016


Author: jamesm
Date: Thu Sep  8 07:58:12 2016
New Revision: 280929

URL: http://llvm.org/viewvc/llvm-project?rev=280929&view=rev
Log:
[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.

Modified:
    llvm/trunk/lib/Target/ARM/ARMTargetTransformInfo.cpp
    llvm/trunk/test/CodeGen/ARM/immcost.ll

Modified: llvm/trunk/lib/Target/ARM/ARMTargetTransformInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/ARMTargetTransformInfo.cpp?rev=280929&r1=280928&r2=280929&view=diff
==============================================================================
--- llvm/trunk/lib/Target/ARM/ARMTargetTransformInfo.cpp (original)
+++ llvm/trunk/lib/Target/ARM/ARMTargetTransformInfo.cpp Thu Sep  8 07:58:12 2016
@@ -69,6 +69,10 @@ int ARMTTIImpl::getIntImmCost(unsigned O
       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);
 }
 

Modified: llvm/trunk/test/CodeGen/ARM/immcost.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/ARM/immcost.ll?rev=280929&r1=280928&r2=280929&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/ARM/immcost.ll (original)
+++ llvm/trunk/test/CodeGen/ARM/immcost.ll Thu Sep  8 07:58:12 2016
@@ -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
+}
+




More information about the llvm-commits mailing list