[PATCH] D21791: [InstCombine] Fix for trunc folding build break

Anna Thomas via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 28 07:10:31 PDT 2016


anna added a comment.

Could think of 3 possible ways to fix the build breakage caused by type mismatch (the test case which showcases the breakage is @trunc_avoid_bitcast):

1. The RAUW  `return replaceInstUsesWith(CI, AvailableVal);` should be `return replaceInstUsesWith( CI, Builder->CreateBitOrPointerCast(AvailableVal, CI.getType(), CI.getName() + ".cast"));`

2. Avoid the RAUW when the `AvailableVal` type is not the same as `DestTy` of trunc.
3. Special case the trunc type in `FindAvailableLoadedValue` (i.e. check for exact match rather than `CastInst::isBitOrNoopPointerCastable(LI->getType(), AccessTy, DL)`) Error-prone solution whose benefit is minimal.

I followed #2.

What #1 does is replace the trunc with a bitcast or PointerCast. While generating bitcast would be useful if `FindAvailableLoadedValue` was used to replace loads, there does not seem to be a *strong* benefit in replacing the trunc with `bitcast` or `pointercast`. Looking at `SelectionDAG::visitBitCast` and all the pointer cast instructions, it may or may not be a noop. I didnot see an obvious benefit (i.e. hold true in all cases) in using `BitOrPointerCast` instead of `trunc`. 
Also, this avoids possible performance regression creeping up due to some specific target lowering or due to optimizations that benefit `trunc` rather than `BitOrPointerCast`.


Repository:
  rL LLVM

http://reviews.llvm.org/D21791





More information about the llvm-commits mailing list