Prevent the folding in DAGCombine if it leads to worse code.
I have troubles with thumb and 'arm without movt/movw', so let me submit the partial change, which leads to better code for 'arm with movt/movw'.
And mark the thumb and 'arm without movt/movw' as TODOs.
Could this use ConstantMaterializationCost from ARMBaseInstrInfo for the costs of materializing the constants? That way it should just work with any architecture or constants, with some simple checking for which will produce the lowest total cost. It might need to include isLegalAddImmediate too, but that should be handling Thumb and Arm already too.
Thanks for your advice. I have changed to using ConstantMaterializationCost, it does work for all arm/thumb targets.
One more concern, this change generates better code for most cases, except the ARMV5/ARMV6 tags in @test_urem_vec in llvm/test/CodeGen/ARM/urem-seteq-illegal-types.ll. The total number of ARMV5 instructions decreases from 38 to 36, and ARMV6 also decreases from 38 to 36. It looks like improvement than regression. But I am sure you can accept such a large change.
So in my previous patch revision, I left ARMv5/v6 as TODO and only did for subtargets with movw/movt.
What is the best form do you think? I can fall back to thumb + arm_with_movt, which I thought to be better.