This is an archive of the discontinued LLVM Phabricator instance.

InstCombine rule for trunc feeding from prior load/store
AbandonedPublic

Authored by anna on Jul 8 2016, 2:48 PM.

Details

Summary

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:

  1. 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

  1. 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.

Diff Detail

Event Timeline

anna updated this revision to Diff 63324.Jul 8 2016, 2:48 PM
anna retitled this revision from to Fix ppcBE break: Avoid instcombine trunc rule for BE layout.
anna updated this object.
anna added a reviewer: reames.
anna added a subscriber: llvm-commits.
anna added a comment.Jul 8 2016, 3:23 PM

I have reverted the change in http://reviews.llvm.org/D21791 for now.

anna retitled this revision from Fix ppcBE break: Avoid instcombine trunc rule for BE layout to InstCombine rule for trunc feeding from prior load/store.Jul 11 2016, 2:03 PM
anna updated this object.
anna updated this revision to Diff 63674.Jul 12 2016, 6:26 AM
anna updated this object.

Add the instcombine rule for LE mode. Add file check prefixes to make sure rule not done in BE.

anna added a comment.Jul 12 2016, 6:36 AM

Summary of why we need the check for Data Layout being Little Endian.
Consider this (pseudo) example:
i16 type (narrow) store at addr a
i32 type (wide) load from addr a
trunc i32 to i16

The load/store of value into memory depends on the layout -- big endian or little endian. However, when loaded into register, the value is stored as MSB...LSB in register. The trunc operation done on the register value extracts the lower order bits. So, we cannot substitute the trunc with the store when the layout is BE. For BE layout, we need to confirm the partial memory contents extracted from the narrow load/store is the *same value* as generated by the trunc.

See example: trunc_load_store (different sized store compared to load at same memory location).

anna abandoned this revision.Feb 16 2017, 12:51 PM

Not working on this currently.