[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
This commit is contained in:
James Molloy 2016-09-08 12:58:12 +00:00
parent 7c7255e40b
commit 753c18f5c0
2 changed files with 22 additions and 0 deletions

View File

@ -69,6 +69,10 @@ int ARMTTIImpl::getIntImmCost(unsigned Opcode, unsigned Idx, const APInt &Imm,
Idx == 1) Idx == 1)
return 0; 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); return getIntImmCost(Imm, Ty);
} }

View File

@ -19,3 +19,21 @@ true:
ret: ret:
ret void 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
}