Index: lib/Target/ARM/ARMISelLowering.h =================================================================== --- lib/Target/ARM/ARMISelLowering.h +++ lib/Target/ARM/ARMISelLowering.h @@ -291,6 +291,14 @@ /// by AM is legal for this target, for a load/store of the specified type. bool isLegalAddressingMode(const DataLayout &DL, const AddrMode &AM, Type *Ty, unsigned AS) const override; + + /// getScalingFactorCost - Return the cost of the scaling used in + /// addressing mode represented by AM. + /// If the AM is supported, the return value must be >= 0. + /// If the AM is not supported, the return value must be negative. + int getScalingFactorCost(const DataLayout &DL, const AddrMode &AM, Type *Ty, + unsigned AS) const override; + bool isLegalT2ScaledAddressingMode(const AddrMode &AM, EVT VT) const; /// isLegalICmpImmediate - Return true if the specified immediate is legal Index: lib/Target/ARM/ARMISelLowering.cpp =================================================================== --- lib/Target/ARM/ARMISelLowering.cpp +++ lib/Target/ARM/ARMISelLowering.cpp @@ -11427,6 +11427,14 @@ return true; } +int ARMTargetLowering::getScalingFactorCost(const DataLayout &DL, + const AddrMode &AM, Type *Ty, + unsigned AS) const { + if (isLegalAddressingMode(DL, AM, Ty, AS)) + return AM.Scale < 0 ? 2 : 0; // negative scaling costs extra cycles + return -1; +} + static bool isLegalT1AddressImmediate(int64_t V, EVT VT) { if (V < 0) Index: test/CodeGen/ARM/lsr-scale-addr-mode.ll =================================================================== --- test/CodeGen/ARM/lsr-scale-addr-mode.ll +++ test/CodeGen/ARM/lsr-scale-addr-mode.ll @@ -1,6 +1,9 @@ ; RUN: llc -mtriple=arm-eabi %s -o - | FileCheck %s ; Should use scaled addressing mode. +; RUN: llc -mtriple=arm-eabi %s -o - | FileCheck %s -check-prefix CHECK-NONEGOFF +; Should not generate negated register offset + define void @sintzero(i32* %a) nounwind { entry: store i32 0, i32* %a @@ -19,4 +22,5 @@ } ; CHECK: lsl{{.*}}#2] +; CHECK-NONEGOFF: [{{r[0-9]+}}, {{r[0-9]+}}, lsl{{.*}}#2]