[PATCH] D22175: Fix ppcBE break: Avoid instcombine trunc rule for BE layout

Anna Thomas via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 8 14:48:53 PDT 2016


anna created this revision.
anna added a reviewer: reames.
anna added a subscriber: llvm-commits.

This change is to avoid the instcombine rule for BE layout.

store i8 0, i8 *%a, align 2
%bca  = bitcast i8* %a to i16*
%wide.load = load i16, i16* %bca, align 2
%lowhalf.1 = trunc i16 %wide.load to i8  <— trunc feeds directly from a load.

This trunc will be the low half in LE machines. 
To get the same content in BE, we’ll need a shr, followed by trunc. 
So, for a BE machine, we cannot replace the trunc value with 0 (in LE we can do that).

http://reviews.llvm.org/D22175

Files:
  lib/Transforms/InstCombine/InstCombineCasts.cpp

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<LoadInst>(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<LoadInst>(Src)) {
     BasicBlock::iterator BBI(*LI);
 
     // Scan a few instructions up from LI and if we find a partial load/store


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D22175.63324.patch
Type: text/x-patch
Size: 802 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160708/d9fa8301/attachment.bin>


More information about the llvm-commits mailing list