[llvm-branch-commits] [llvm-branch] r95758 - in /llvm/branches/Apple/Hermes: lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp test/CodeGen/X86/zext-trunc.ll
Evan Cheng
evan.cheng at apple.com
Tue Feb 9 18:22:32 PST 2010
Author: evancheng
Date: Tue Feb 9 20:22:31 2010
New Revision: 95758
URL: http://llvm.org/viewvc/llvm-project?rev=95758&view=rev
Log:
Merge 95757.
Added:
llvm/branches/Apple/Hermes/test/CodeGen/X86/zext-trunc.ll
Modified:
llvm/branches/Apple/Hermes/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
Modified: llvm/branches/Apple/Hermes/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Hermes/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp?rev=95758&r1=95757&r2=95758&view=diff
==============================================================================
--- llvm/branches/Apple/Hermes/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp (original)
+++ llvm/branches/Apple/Hermes/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp Tue Feb 9 20:22:31 2010
@@ -457,6 +457,21 @@
};
}
+/// TrivialTruncElim - Eliminate some trivial nops that can result from
+/// ShrinkDemandedOps: (trunc (ext n)) -> n.
+static bool TrivialTruncElim(SDValue Op,
+ TargetLowering::TargetLoweringOpt &TLO) {
+ SDValue N0 = Op.getOperand(0);
+ EVT VT = Op.getValueType();
+ if ((N0.getOpcode() == ISD::ZERO_EXTEND ||
+ N0.getOpcode() == ISD::SIGN_EXTEND ||
+ N0.getOpcode() == ISD::ANY_EXTEND) &&
+ N0.getOperand(0).getValueType() == VT) {
+ return TLO.CombineTo(Op, N0.getOperand(0));
+ }
+ return false;
+}
+
/// ShrinkDemandedOps - A late transformation pass that shrink expressions
/// using TargetLowering::TargetLoweringOpt::ShrinkDemandedOp. It converts
/// x+y to (VT)((SmallVT)x+(SmallVT)y) if the casts are free.
@@ -489,7 +504,9 @@
APInt Demanded = APInt::getAllOnesValue(BitWidth);
APInt KnownZero, KnownOne;
if (TLI.SimplifyDemandedBits(SDValue(N, 0), Demanded,
- KnownZero, KnownOne, TLO)) {
+ KnownZero, KnownOne, TLO) ||
+ (N->getOpcode() == ISD::TRUNCATE &&
+ TrivialTruncElim(SDValue(N, 0), TLO))) {
// Revisit the node.
Worklist.erase(std::remove(Worklist.begin(), Worklist.end(), N),
Worklist.end());
Added: llvm/branches/Apple/Hermes/test/CodeGen/X86/zext-trunc.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Hermes/test/CodeGen/X86/zext-trunc.ll?rev=95758&view=auto
==============================================================================
--- llvm/branches/Apple/Hermes/test/CodeGen/X86/zext-trunc.ll (added)
+++ llvm/branches/Apple/Hermes/test/CodeGen/X86/zext-trunc.ll Tue Feb 9 20:22:31 2010
@@ -0,0 +1,13 @@
+; RUN: llc < %s -march=x86-64 | FileCheck %s
+; rdar://7570931
+
+define i64 @foo(i64 %a, i64 %b) nounwind {
+; CHECK: foo:
+; CHECK: leal
+; CHECK-NOT: movl
+; CHECK: ret
+ %c = add i64 %a, %b
+ %d = trunc i64 %c to i32
+ %e = zext i32 %d to i64
+ ret i64 %e
+}
More information about the llvm-branch-commits
mailing list