[llvm-branch-commits] [llvm-branch] r109304 - in /llvm/branches/Apple/williamson: lib/CodeGen/SelectionDAG/TargetLowering.cpp lib/CodeGen/SelectionDAG/TargetLowering.cpp.orig test/CodeGen/X86/shl-anyext.ll

Daniel Dunbar daniel at zuster.org
Fri Jul 23 18:01:55 PDT 2010


Author: ddunbar
Date: Fri Jul 23 20:01:55 2010
New Revision: 109304

URL: http://llvm.org/viewvc/llvm-project?rev=109304&view=rev
Log:
Merge r109242:
--
Author: Dan Gohman <gohman at apple.com>
Date:   Fri Jul 23 18:03:30 2010 +0000

    DAGCombine (shl (anyext x, c)) to (anyext (shl x, c)) if the high bits
    are not demanded. This often allows the anyext to be folded away.

Added:
    llvm/branches/Apple/williamson/lib/CodeGen/SelectionDAG/TargetLowering.cpp.orig
      - copied, changed from r109115, llvm/branches/Apple/williamson/lib/CodeGen/SelectionDAG/TargetLowering.cpp
    llvm/branches/Apple/williamson/test/CodeGen/X86/shl-anyext.ll
Modified:
    llvm/branches/Apple/williamson/lib/CodeGen/SelectionDAG/TargetLowering.cpp

Modified: llvm/branches/Apple/williamson/lib/CodeGen/SelectionDAG/TargetLowering.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/williamson/lib/CodeGen/SelectionDAG/TargetLowering.cpp?rev=109304&r1=109303&r2=109304&view=diff
==============================================================================
--- llvm/branches/Apple/williamson/lib/CodeGen/SelectionDAG/TargetLowering.cpp (original)
+++ llvm/branches/Apple/williamson/lib/CodeGen/SelectionDAG/TargetLowering.cpp Fri Jul 23 20:01:55 2010
@@ -1361,9 +1361,29 @@
         }
       }      
       
-      if (SimplifyDemandedBits(Op.getOperand(0), NewMask.lshr(ShAmt),
+      if (SimplifyDemandedBits(InOp, NewMask.lshr(ShAmt),
                                KnownZero, KnownOne, TLO, Depth+1))
         return true;
+
+      // Convert (shl (anyext x, c)) to (anyext (shl x, c)) if the high bits
+      // are not demanded. This will likely allow the anyext to be folded away.
+      if (InOp.getNode()->getOpcode() == ISD::ANY_EXTEND) {
+        SDValue InnerOp = InOp.getNode()->getOperand(0);
+        EVT InnerVT = InnerOp.getValueType();
+        if ((APInt::getHighBitsSet(BitWidth,
+                                   BitWidth - InnerVT.getSizeInBits()) &
+               DemandedMask) == 0 &&
+            isTypeDesirableForOp(ISD::SHL, InnerVT)) {
+          SDValue NarrowShl =
+            TLO.DAG.getNode(ISD::SHL, dl, InnerVT, InnerOp,
+                            TLO.DAG.getConstant(ShAmt, InnerVT));
+          return
+            TLO.CombineTo(Op,
+                          TLO.DAG.getNode(ISD::ANY_EXTEND, dl, Op.getValueType(),
+                                          NarrowShl));
+        }
+      }
+
       KnownZero <<= SA->getZExtValue();
       KnownOne  <<= SA->getZExtValue();
       // low bits known zero.

Copied: llvm/branches/Apple/williamson/lib/CodeGen/SelectionDAG/TargetLowering.cpp.orig (from r109115, llvm/branches/Apple/williamson/lib/CodeGen/SelectionDAG/TargetLowering.cpp)
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/williamson/lib/CodeGen/SelectionDAG/TargetLowering.cpp.orig?p2=llvm/branches/Apple/williamson/lib/CodeGen/SelectionDAG/TargetLowering.cpp.orig&p1=llvm/branches/Apple/williamson/lib/CodeGen/SelectionDAG/TargetLowering.cpp&r1=109115&r2=109304&rev=109304&view=diff
==============================================================================
    (empty)

Added: llvm/branches/Apple/williamson/test/CodeGen/X86/shl-anyext.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/williamson/test/CodeGen/X86/shl-anyext.ll?rev=109304&view=auto
==============================================================================
--- llvm/branches/Apple/williamson/test/CodeGen/X86/shl-anyext.ll (added)
+++ llvm/branches/Apple/williamson/test/CodeGen/X86/shl-anyext.ll Fri Jul 23 20:01:55 2010
@@ -0,0 +1,18 @@
+; RUN: llc -march=x86-64 < %s | FileCheck %s
+
+; Codegen should be able to use a 32-bit shift instead of a 64-bit shift.
+; CHECK: shll $16
+
+define fastcc void @test(i32 %level, i64 %a, i64 %b, i64 %c, i64 %d, i32* %p) nounwind {
+if.end523:                                        ; preds = %if.end453
+  %conv7981749 = zext i32 %level to i64           ; <i64> [#uses=1]
+  %and799 = shl i64 %conv7981749, 16              ; <i64> [#uses=1]
+  %shl800 = and i64 %and799, 16711680             ; <i64> [#uses=1]
+  %or801 = or i64 %shl800, %a                     ; <i64> [#uses=1]
+  %or806 = or i64 %or801, %b                      ; <i64> [#uses=1]
+  %or811 = or i64 %or806, %c                      ; <i64> [#uses=1]
+  %or819 = or i64 %or811, %d                      ; <i64> [#uses=1]
+  %conv820 = trunc i64 %or819 to i32              ; <i32> [#uses=1]
+  store i32 %conv820, i32* %p
+  ret void
+}





More information about the llvm-branch-commits mailing list