Index: lib/Target/ARM/ARMISelDAGToDAG.cpp =================================================================== --- lib/Target/ARM/ARMISelDAGToDAG.cpp +++ lib/Target/ARM/ARMISelDAGToDAG.cpp @@ -451,8 +451,9 @@ if (Subtarget->isThumb()) { if (Val <= 255) return 1; // MOV if (Subtarget->hasV6T2Ops() && - (Val <= 0xffff || ARM_AM::getT2SOImmValSplatVal(Val) != -1)) - return 1; // MOVW + (Val <= 0xffff || ARM_AM::getT2SOImmVal(Val) != -1 || // MOV + MOVW + ARM_AM::getT2SOImmVal(~Val) != -1)) // MVN + return 1; 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/shifter_operand.ll =================================================================== --- test/CodeGen/ARM/shifter_operand.ll +++ test/CodeGen/ARM/shifter_operand.ll @@ -256,3 +256,26 @@ ret { i32, i32 } %ret } + +declare dso_local i32 @eat_const(i32) + +define hidden i32 @no_litpool() minsize optsize { +; CHECK-LABEL: no_litpool: +; CHECK: mov{{.*}} r0, #65536 +; CHECK: mov{{.*}} r0, #-134217728 +; CHECK: mvn r0, #-134217728 +entry: + %call0 = tail call i32 @eat_const(i32 65536) + %call1 = tail call i32 @eat_const(i32 -134217728) + %call2 = tail call i32 @eat_const(i32 134217727) + ret i32 %call2 +} + +define hidden i32 @litpool() minsize optsize { +; CHECK-LABEL: litpool: +; CHECK: ldr r0, {{.*}}LCPI{{.*}} +; CHECK-NEXT: b {{.*}}eat_const +entry: + %call1 = tail call i32 @eat_const(i32 8388601) + ret i32 %call1 +}