llvm.org GIT mirror llvm / 046632f
Now that ShrinkDemandedOps() is separated out from DAG combine. It sometimes leave some obvious nops which dag combine used to clean up afterwards e.g. (trunk (ext n)) -> n. Look for them and squash them. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@95757 91177308-0d34-0410-b5e6-96231b3b80d8 Evan Cheng 10 years ago
2 changed file(s) with 31 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
456456 };
457457 }
458458
459 /// TrivialTruncElim - Eliminate some trivial nops that can result from
460 /// ShrinkDemandedOps: (trunc (ext n)) -> n.
461 static bool TrivialTruncElim(SDValue Op,
462 TargetLowering::TargetLoweringOpt &TLO) {
463 SDValue N0 = Op.getOperand(0);
464 EVT VT = Op.getValueType();
465 if ((N0.getOpcode() == ISD::ZERO_EXTEND ||
466 N0.getOpcode() == ISD::SIGN_EXTEND ||
467 N0.getOpcode() == ISD::ANY_EXTEND) &&
468 N0.getOperand(0).getValueType() == VT) {
469 return TLO.CombineTo(Op, N0.getOperand(0));
470 }
471 return false;
472 }
473
459474 /// ShrinkDemandedOps - A late transformation pass that shrink expressions
460475 /// using TargetLowering::TargetLoweringOpt::ShrinkDemandedOp. It converts
461476 /// x+y to (VT)((SmallVT)x+(SmallVT)y) if the casts are free.
488503 APInt Demanded = APInt::getAllOnesValue(BitWidth);
489504 APInt KnownZero, KnownOne;
490505 if (TLI.SimplifyDemandedBits(SDValue(N, 0), Demanded,
491 KnownZero, KnownOne, TLO)) {
506 KnownZero, KnownOne, TLO) ||
507 (N->getOpcode() == ISD::TRUNCATE &&
508 TrivialTruncElim(SDValue(N, 0), TLO))) {
492509 // Revisit the node.
493510 Worklist.erase(std::remove(Worklist.begin(), Worklist.end(), N),
494511 Worklist.end());
0 ; RUN: llc < %s -march=x86-64 | FileCheck %s
1 ; rdar://7570931
2
3 define i64 @foo(i64 %a, i64 %b) nounwind {
4 ; CHECK: foo:
5 ; CHECK: leal
6 ; CHECK-NOT: movl
7 ; CHECK: ret
8 %c = add i64 %a, %b
9 %d = trunc i64 %c to i32
10 %e = zext i32 %d to i64
11 ret i64 %e
12 }