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 but 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
Load being used:
%138 = load float, float* %m_x.i527, align 4, !dbg !447
Trunc being replaced:
%155 = trunc i64 %140 to i32, !dbg !470
This change fixes the above issue, and I've added a testcase to make sure that we don't fail the assertion (@trunc_avoid_bitcast). Also, couple of other testcases added.