[llvm-commits] CVS: llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp

Chris Lattner sabre at nondot.org
Mon Sep 18 22:02:53 PDT 2006



Changes in directory llvm/lib/CodeGen/SelectionDAG:

SelectionDAG.cpp updated: 1.339 -> 1.340
---
Log message:

Fold extract_element(cst) to cst


---
Diffs of the changes:  (+8 -2)

 SelectionDAG.cpp |   10 ++++++++--
 1 files changed, 8 insertions(+), 2 deletions(-)


Index: llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
diff -u llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp:1.339 llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp:1.340
--- llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp:1.339	Mon Sep 18 23:51:23 2006
+++ llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp	Tue Sep 19 00:02:39 2006
@@ -1330,12 +1330,18 @@
     break;
   }
   case ISD::EXTRACT_ELEMENT:
+    assert(N2C && (unsigned)N2C->getValue() < 2 && "Bad EXTRACT_ELEMENT!");
+    
     // EXTRACT_ELEMENT of BUILD_PAIR is often formed while legalize is expanding
     // 64-bit integers into 32-bit parts.  Instead of building the extract of
     // the BUILD_PAIR, only to have legalize rip it apart, just do it now. 
-    if (N2C && N1.getOpcode() == ISD::BUILD_PAIR) {
-      assert((unsigned)N2C->getValue() < 2 && "Bad EXTRACT_ELEMENT!");
+    if (N1.getOpcode() == ISD::BUILD_PAIR)
       return N1.getOperand(N2C->getValue());
+    
+    // EXTRACT_ELEMENT of a constant int is also very common.
+    if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N1)) {
+      unsigned Shift = MVT::getSizeInBits(VT) * N2C->getValue();
+      return getConstant(C->getValue() >> Shift, VT);
     }
     break;
 






More information about the llvm-commits mailing list