[PATCH] D16598: DAGCombiner: don't do (zext (trunc x)) -> (and x, 65535) if !hasOneUse(trunc x) and zext is free

escha via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 26 12:54:33 PST 2016


escha created this revision.
escha added a reviewer: resistor.
escha added a subscriber: llvm-commits.
escha set the repository for this revision to rL LLVM.

This came up in our out of tree target and results in a lot of cases where 'x' ends up used by both (trunc x) and (and x, 65535), causing x to no longer have one use when it really should (and ending up materializing wasted instructions later).

Repository:
  rL LLVM

http://reviews.llvm.org/D16598

Files:
  lib/CodeGen/SelectionDAG/DAGCombiner.cpp

Index: lib/CodeGen/SelectionDAG/DAGCombiner.cpp
===================================================================
--- lib/CodeGen/SelectionDAG/DAGCombiner.cpp
+++ lib/CodeGen/SelectionDAG/DAGCombiner.cpp
@@ -6111,8 +6111,10 @@
   }
 
   // fold (zext (truncate x)) -> (and x, mask)
+  // Only do this if zext isn't free or (truncate x) has one use.
   if (N0.getOpcode() == ISD::TRUNCATE &&
-      (!LegalOperations || TLI.isOperationLegal(ISD::AND, VT))) {
+      (!LegalOperations || TLI.isOperationLegal(ISD::AND, VT)) &&
+      (N0.hasOneUse() || !TLI.isZExtFree(N0.getValueType(), VT))) {
 
     // fold (zext (truncate (load x))) -> (zext (smaller load x))
     // fold (zext (truncate (srl (load x), c))) -> (zext (smaller load (x+c/n)))


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D16598.46037.patch
Type: text/x-patch
Size: 747 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160126/d2c863a9/attachment.bin>


More information about the llvm-commits mailing list