diff options
| -rw-r--r-- | llvm/lib/Target/ARM/ARMTargetTransformInfo.cpp | 4 | ||||
| -rw-r--r-- | llvm/test/CodeGen/ARM/immcost.ll | 17 |
2 files changed, 21 insertions, 0 deletions
diff --git a/llvm/lib/Target/ARM/ARMTargetTransformInfo.cpp b/llvm/lib/Target/ARM/ARMTargetTransformInfo.cpp index 13d57c0934a..10e6297ef1e 100644 --- a/llvm/lib/Target/ARM/ARMTargetTransformInfo.cpp +++ b/llvm/lib/Target/ARM/ARMTargetTransformInfo.cpp @@ -73,6 +73,10 @@ int ARMTTIImpl::getIntImmCost(unsigned Opcode, unsigned Idx, const APInt &Imm, // Conversion to BIC is free, and means we can use ~Imm instead. return std::min(getIntImmCost(Imm, Ty), getIntImmCost(~Imm, Ty)); + if (Opcode == Instruction::Add) + // Conversion to SUB is free, and means we can use -Imm instead. + return std::min(getIntImmCost(Imm, Ty), getIntImmCost(-Imm, Ty)); + if (Opcode == Instruction::ICmp && Imm.isNegative() && Ty->getIntegerBitWidth() == 32) { int64_t NegImm = -Imm.getSExtValue(); diff --git a/llvm/test/CodeGen/ARM/immcost.ll b/llvm/test/CodeGen/ARM/immcost.ll index 43a4989e6bd..1b05ffbfac9 100644 --- a/llvm/test/CodeGen/ARM/immcost.ll +++ b/llvm/test/CodeGen/ARM/immcost.ll @@ -71,3 +71,20 @@ true: ret: ret void } + +; CHECK: Function: test_add_neg +; CHECK-NOT: Collect constant i32 -5 +define void @test_add_neg(i1 %cond, i32 %arg, i32 %arg2) { +entry: + %a = add i32 %arg, -5 + call void @g(i32 %a) + br i1 %cond, label %true, label %ret + +true: + %b = add i32 %arg2, -5 + call void @g(i32 %b) + br label %ret + +ret: + ret void +} |

