We can fold truncs whose operand feeds from a load, if the trunc value is available through a prior load/store.
This change is from: http://reviews.llvm.org/D21246, which folded the trunc.
There were 2 problem that cropped up in the builds:
- missed the bitcast or ptrtoint/inttoptr required in the RAUW call, when the load type didnt match the prior load/store type.
The change was reverted in: r273703 due to fail in Chromium and sanitizer build. This was the bad RAUW assertion:
Assertion failed: New->getType() == getType() && "replaceAllUses of value with new value of different type!", file ..\lib\IR\Value.cpp, line 375
- The rule does not work in BE mode. Got one failure in clang-ppc64be-linux-lnt in test case: MultiSource/Applications/lemon/lemon.execution_time. This instcombine rule involves examining if the trunc value of a wider load is available in a narrow load/store. The langref states that truncs would throw away the high order bit and extract the contents from low order bits. To work in BE mode, we need to pass in the correct offset along with DestTy to FindAvailableLoadedValue. Note that this is similar to the IR updates done in GVN widening (see GetLoadValueForLoad) and vectorization for LE versus BE modes.