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.
I'm not following why you need this new interface. Why can't we reuse the existing interface? We have the load instruction don't we?
... I think I see it. The issue is we need to use the narrower type right? The comment seams to be stale. You're really using the size of the access ty. Can you adjust the comment to make this more obvious.
p.s. Please don't repeat function comments in the cpp. And yes, I know the near by code does. This is older style.