[llvm-branch-commits] [llvm-branch] r118526 - in /llvm/branches/Apple/whitney: lib/CodeGen/SelectionDAG/DAGCombiner.cpp test/CodeGen/X86/narrow-shl-load.ll
Daniel Dunbar
daniel at zuster.org
Tue Nov 9 09:28:13 PST 2010
Author: ddunbar
Date: Tue Nov 9 11:28:13 2010
New Revision: 118526
URL: http://llvm.org/viewvc/llvm-project?rev=118526&view=rev
Log:
Merge r118143:
--
Author: Dan Gohman <gohman at apple.com>
Date: Wed Nov 3 01:47:46 2010 +0000
Fix DAGCombiner to avoid going into an infinite loop when it
encounters (and:i64 (shl:i64 (load:i64), 1), 0xffffffff).
This fixes rdar://8606584.
Added:
llvm/branches/Apple/whitney/test/CodeGen/X86/narrow-shl-load.ll
Modified:
llvm/branches/Apple/whitney/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
Modified: llvm/branches/Apple/whitney/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/whitney/lib/CodeGen/SelectionDAG/DAGCombiner.cpp?rev=118526&r1=118525&r2=118526&view=diff
==============================================================================
--- llvm/branches/Apple/whitney/lib/CodeGen/SelectionDAG/DAGCombiner.cpp (original)
+++ llvm/branches/Apple/whitney/lib/CodeGen/SelectionDAG/DAGCombiner.cpp Tue Nov 9 11:28:13 2010
@@ -3667,6 +3667,20 @@
// fold (zext (truncate x)) -> (and x, mask)
if (N0.getOpcode() == ISD::TRUNCATE &&
(!LegalOperations || TLI.isOperationLegal(ISD::AND, VT))) {
+
+ // fold (zext (truncate (load x))) -> (zext (smaller load x))
+ // fold (zext (truncate (srl (load x), c))) -> (zext (smaller load (x+c/n)))
+ SDValue NarrowLoad = ReduceLoadWidth(N0.getNode());
+ if (NarrowLoad.getNode()) {
+ SDNode* oye = N0.getNode()->getOperand(0).getNode();
+ if (NarrowLoad.getNode() != N0.getNode()) {
+ CombineTo(N0.getNode(), NarrowLoad);
+ // CombineTo deleted the truncate, if needed, but not what's under it.
+ AddToWorkList(oye);
+ }
+ return SDValue(N, 0); // Return N so it doesn't get rechecked!
+ }
+
SDValue Op = N0.getOperand(0);
if (Op.getValueType().bitsLT(VT)) {
Op = DAG.getNode(ISD::ANY_EXTEND, N->getDebugLoc(), VT, Op);
@@ -4102,6 +4116,17 @@
}
}
+ // If the load is shifted left (and the result isn't shifted back right),
+ // we can fold the truncate through the shift.
+ unsigned ShLeftAmt = 0;
+ if (ShAmt == 0 && N0.getOpcode() == ISD::SHL && N0.hasOneUse() &&
+ TLI.isNarrowingProfitable(N0.getValueType(), VT)) {
+ if (ConstantSDNode *N01 = dyn_cast<ConstantSDNode>(N0.getOperand(1))) {
+ ShLeftAmt = N01->getZExtValue();
+ N0 = N0.getOperand(0);
+ }
+ }
+
// Do not generate loads of non-round integer types since these can
// be expensive (and would be wrong if the type is not byte sized).
if (isa<LoadSDNode>(N0) && N0.hasOneUse() && ExtVT.isRound() &&
@@ -4140,8 +4165,18 @@
DAG.ReplaceAllUsesOfValueWith(N0.getValue(1), Load.getValue(1),
&DeadNodes);
+ // Shift the result left, if we've swallowed a left shift.
+ SDValue Result = Load;
+ if (ShLeftAmt != 0) {
+ EVT ShImmTy = getShiftAmountTy();
+ if (!isUIntN(ShImmTy.getSizeInBits(), ShLeftAmt))
+ ShImmTy = VT;
+ Result = DAG.getNode(ISD::SHL, N0.getDebugLoc(), VT,
+ Result, DAG.getConstant(ShLeftAmt, ShImmTy));
+ }
+
// Return the new loaded value.
- return Load;
+ return Result;
}
return SDValue();
Added: llvm/branches/Apple/whitney/test/CodeGen/X86/narrow-shl-load.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/whitney/test/CodeGen/X86/narrow-shl-load.ll?rev=118526&view=auto
==============================================================================
--- llvm/branches/Apple/whitney/test/CodeGen/X86/narrow-shl-load.ll (added)
+++ llvm/branches/Apple/whitney/test/CodeGen/X86/narrow-shl-load.ll Tue Nov 9 11:28:13 2010
@@ -0,0 +1,32 @@
+; RUN: llc -march=x86-64 < %s
+
+; DAGCombiner should fold this code in finite time.
+
+; rdar://8606584
+
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
+target triple = "x86_64-pc-linux-gnu"
+
+define void @D() nounwind readnone {
+bb.nph:
+ br label %while.cond
+
+while.cond: ; preds = %while.cond, %bb.nph
+ %tmp6 = load i32* undef, align 4
+ %and = or i64 undef, undef
+ %conv11 = zext i32 undef to i64
+ %conv14 = zext i32 %tmp6 to i64
+ %shl15 = shl i64 %conv14, 1
+ %shl15.masked = and i64 %shl15, 4294967294
+ %and17 = or i64 %shl15.masked, %conv11
+ %add = add i64 %and17, 1
+ %xor = xor i64 %add, %and
+ %tmp20 = load i64* undef, align 8
+ %add21 = add i64 %xor, %tmp20
+ %conv22 = trunc i64 %add21 to i32
+ store i32 %conv22, i32* undef, align 4
+ br i1 false, label %while.end, label %while.cond
+
+while.end: ; preds = %while.cond
+ ret void
+}
More information about the llvm-branch-commits
mailing list