Index: lib/Transforms/InstCombine/InstCombineCasts.cpp =================================================================== --- lib/Transforms/InstCombine/InstCombineCasts.cpp +++ lib/Transforms/InstCombine/InstCombineCasts.cpp @@ -577,8 +577,10 @@ return I; // When trunc operand is a widened load, see if we can get the value from a - // previous store/load - if (auto *LI = dyn_cast(Src)) { + // previous store/load. This rule works for LE layout only. For a BE layout, + // we would require a shr and a trunc to refer to same content that an LE + // memory layout refers through a trunc. + if (DL.isLittleEndian() && auto *LI = dyn_cast(Src)) { BasicBlock::iterator BBI(*LI); // Scan a few instructions up from LI and if we find a partial load/store