Index: lib/Target/ARM/ARMISelDAGToDAG.cpp =================================================================== --- lib/Target/ARM/ARMISelDAGToDAG.cpp +++ lib/Target/ARM/ARMISelDAGToDAG.cpp @@ -476,7 +476,9 @@ unsigned ARMDAGToDAGISel::ConstantMaterializationCost(unsigned Val) const { if (Subtarget->isThumb()) { if (Val <= 255) return 1; // MOV - if (Subtarget->hasV6T2Ops() && Val <= 0xffff) return 1; // MOVW + if (Subtarget->hasV6T2Ops() && + (Val <= 0xffff || ARM_AM::getT2SOImmValSplatVal(Val) != -1)) + return 1; // MOVW if (Val <= 510) return 2; // MOV + ADDi8 if (~Val <= 255) return 2; // MOV + MVN if (ARM_AM::isThumbImmShiftedVal(Val)) return 2; // MOV + LSL Index: test/CodeGen/ARM/subtarget-no-movt.ll =================================================================== --- test/CodeGen/ARM/subtarget-no-movt.ll +++ test/CodeGen/ARM/subtarget-no-movt.ll @@ -42,4 +42,21 @@ ret i32 %1 } +; NO-OPTION-LABEL: {{_?}}foo2 +; NO-OPTION: mov.w r0, #-536813568 +; NO-OPTION-LABEL-NOT: .long + +; USE-MOVT-LABEL: {{_?}}foo2 +; USE-MOVT: mov.w r0, #-536813568 +; USE-MOVT-NOT: .long + +; NO-USE-MOVT-LABEL: {{_?}}foo2 +; NO-USE-MOVT: mov.w r0, #-536813568 +; NO-USE-MOVT-NOT: .long +define i32 @foo2() { + %1 = load i32, i32* inttoptr (i32 -536813568 to i32*) ; load from 0xe000e000 + ret i32 %1 +} + + attributes #0 = { "target-features"="+no-movt" }