[InstCombine] foldAddWithConstant(): don't deal with non-immediate constants
authorRoman Lebedev <lebedev.ri@gmail.com>
Wed, 7 Apr 2021 16:46:30 +0000 (19:46 +0300)
committerRoman Lebedev <lebedev.ri@gmail.com>
Wed, 7 Apr 2021 16:50:19 +0000 (19:50 +0300)
commit24f67473dd1253f484e10fd5dfbed95489487b60
treea4b9aff2e78f2b7bf603b0457f9c31b2ce829d10
parent48fa06f70b07fc195a07bfb67ee42cfd307ca450
[InstCombine] foldAddWithConstant(): don't deal with non-immediate constants

All of the code that handles general constant here (other than the more
restrictive APInt-dealing code) expects that it is an immediate,
because otherwise we won't actually fold the constants, and increase
instruction count. And it isn't obvious why we'd be okay with
increasing the number of constant expressions,
those still will have to be run..

But after 2829094a8e252d04f13aabdf6f416c42a06af695
this could also cause endless combine loops.
So actually properly restrict this code to immediates.
llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
llvm/test/Transforms/InstCombine/sub-from-sub.ll