[PATCH] DAGCombiner check for legal ExtLoad operation before folding (aext (zextload x)) -> (aext (truncate (*extload x)))

Stanislav Mekhanoshin stanislav.mekhanoshin at amd.com
Mon Apr 7 06:34:28 PDT 2014


rampitec added you to the CC list for the revision "DAGCombiner check for legal ExtLoad operation before folding (aext (zextload x)) -> (aext (truncate (*extload x)))".

Hi baldrick,

Our custom BE does not support extloads from i8 and i16 right into i64, but there are no legal i8 and i16 types either, only i32 and i64 are legal. So we have custom lowering for such loads which does extload from a sub-dword type to i32 register and then generates extension from i32 to i64. This is the only way the HW can do this is fact.

The DAGCombiner detects double extension and folds it back to a single extending load from a sub-dword to i64, which is marked by BE as custom, not legal. This results in "cannot select" error. Custom lowering is not called anymore after the legalization (if it does that would incur an endless loop, I suppose).

The working solution is to check in DAGCombiner if a requested ext load operation is legal and do not perform optimization if it is not.

Both zext and sext cases are guarded with such check, but not aext.

Addresses Bugzilla #19348.

http://reviews.llvm.org/D3295

Files:
  DAGCombiner.cpp

Index: DAGCombiner.cpp
===================================================================
--- DAGCombiner.cpp
+++ DAGCombiner.cpp
@@ -5507,16 +5507,19 @@
       !ISD::isNON_EXTLoad(N0.getNode()) && ISD::isUNINDEXEDLoad(N0.getNode()) &&
       N0.hasOneUse()) {
     LoadSDNode *LN0 = cast<LoadSDNode>(N0);
+    ISD::LoadExtType ExtType = LN0->getExtensionType();
     EVT MemVT = LN0->getMemoryVT();
-    SDValue ExtLoad = DAG.getExtLoad(LN0->getExtensionType(), SDLoc(N),
-                                     VT, LN0->getChain(), LN0->getBasePtr(),
-                                     MemVT, LN0->getMemOperand());
-    CombineTo(N, ExtLoad);
-    CombineTo(N0.getNode(),
-              DAG.getNode(ISD::TRUNCATE, SDLoc(N0),
-                          N0.getValueType(), ExtLoad),
-              ExtLoad.getValue(1));
-    return SDValue(N, 0);   // Return N so it doesn't get rechecked!
+    if (!LegalOperations || TLI.isLoadExtLegal(ExtType, MemVT)) {
+      SDValue ExtLoad = DAG.getExtLoad(ExtType, SDLoc(N),
+                                       VT, LN0->getChain(), LN0->getBasePtr(),
+                                       MemVT, LN0->getMemOperand());
+      CombineTo(N, ExtLoad);
+      CombineTo(N0.getNode(),
+                DAG.getNode(ISD::TRUNCATE, SDLoc(N0),
+                            N0.getValueType(), ExtLoad),
+                ExtLoad.getValue(1));
+      return SDValue(N, 0);   // Return N so it doesn't get rechecked!
+    }
   }
 
   if (N0.getOpcode() == ISD::SETCC) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D3295.1.patch
Type: text/x-patch
Size: 1507 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140407/e8ea676d/attachment.bin>


More information about the llvm-commits mailing list