[llvm] r344320 - [DAGCombiner] rearrange extract_element+bitcast fold; NFC

Sanjay Patel via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 11 16:56:56 PDT 2018


Author: spatel
Date: Thu Oct 11 16:56:56 2018
New Revision: 344320

URL: http://llvm.org/viewvc/llvm-project?rev=344320&view=rev
Log:
[DAGCombiner] rearrange extract_element+bitcast fold; NFC
  
I want to add another pattern here that includes scalar_to_vector,
so this makes that patch smaller. I was hoping to remove the
hasOneUse() check because it shouldn't be necessary for common
codegen, but an AMDGPU test has a comment suggesting that the
extra check makes things better on one of those targets.


Modified:
    llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
    llvm/trunk/test/CodeGen/X86/extract-insert.ll

Modified: llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp?rev=344320&r1=344319&r2=344320&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp (original)
+++ llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp Thu Oct 11 16:56:56 2018
@@ -15499,13 +15499,15 @@ SDValue DAGCombiner::visitEXTRACT_VECTOR
     // converts.
   }
 
-  // extract_vector_elt (v2i32 (bitcast i64:x)), EltTrunc -> i32 (trunc i64:x)
-  bool isLE = DAG.getDataLayout().isLittleEndian();
-  unsigned EltTrunc = isLE ? 0 : VT.getVectorNumElements() - 1;
-  if (ConstEltNo && InVec.getOpcode() == ISD::BITCAST && InVec.hasOneUse() &&
-      ConstEltNo->getZExtValue() == EltTrunc && VT.isInteger()) {
+  if (ConstEltNo && InVec.getOpcode() == ISD::BITCAST) {
+    // The vector index of the LSBs of the source depend on the endian-ness.
+    bool IsLE = DAG.getDataLayout().isLittleEndian();
+
+    // extract_elt (v2i32 (bitcast i64:x)), BCTruncElt -> i32 (trunc i64:x)
+    unsigned BCTruncElt = IsLE ? 0 : VT.getVectorNumElements() - 1;
     SDValue BCSrc = InVec.getOperand(0);
-    if (BCSrc.getValueType().isScalarInteger())
+    if (InVec.hasOneUse() && ConstEltNo->getZExtValue() == BCTruncElt &&
+        VT.isInteger() && BCSrc.getValueType().isScalarInteger())
       return DAG.getNode(ISD::TRUNCATE, SDLoc(N), NVT, BCSrc);
   }
 

Modified: llvm/trunk/test/CodeGen/X86/extract-insert.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/extract-insert.ll?rev=344320&r1=344319&r2=344320&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/extract-insert.ll (original)
+++ llvm/trunk/test/CodeGen/X86/extract-insert.ll Thu Oct 11 16:56:56 2018
@@ -28,6 +28,10 @@ define i8 @extractelt_bitcast(i32 %x) no
   ret i8 %ext
 }
 
+; TODO: This should have folded to avoid vector ops, but the transform
+; is guarded by 'hasOneUse'. That limitation apparently makes some AMDGPU 
+; codegen better.
+
 define i8 @extractelt_bitcast_extra_use(i32 %x, <4 x i8>* %p) nounwind {
 ; X86-LABEL: extractelt_bitcast_extra_use:
 ; X86:       # %bb.0:




More information about the llvm-commits mailing list