Changes in directory llvm/lib/CodeGen/SelectionDAG:
DAGCombiner.cpp updated: 1.111 -> 1.112 --- Log message: Fold "and (LOAD P), 255" -> zextload. This allows us to compile: unsigned foo3(unsigned *P) { return *P & 255; } as: _foo3: lbz r3, 3(r3) blr instead of: _foo3: lwz r2, 0(r3) rlwinm r3, r2, 0, 24, 31 blr and: unsigned short foo2(float a) { return a; } as: _foo2: fctiwz f0, f1 stfd f0, -8(r1) lhz r3, -2(r1) blr instead of: _foo2: fctiwz f0, f1 stfd f0, -8(r1) lwz r2, -4(r1) rlwinm r3, r2, 0, 16, 31 blr --- Diffs of the changes: (+33 -0) DAGCombiner.cpp | 33 +++++++++++++++++++++++++++++++++ 1 files changed, 33 insertions(+) Index: llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp diff -u llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp:1.111 llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp:1.112 --- llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp:1.111 Tue Feb 28 00:23:04 2006 +++ llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp Tue Feb 28 00:35:35 2006 @@ -1042,6 +1042,39 @@ return SDOperand(); } } + + // fold (and (load x), 255) -> (zextload x) + if (N1C && N0.getOpcode() == ISD::LOAD && N0.hasOneUse()) { + MVT::ValueType EVT; + if (N1C->getValue() == 255) + EVT = MVT::i8; + else if (N1C->getValue() == 65535) + EVT = MVT::i16; + else if (N1C->getValue() == ~0U) + EVT = MVT::i32; + else + EVT = MVT::Other; + if (EVT != MVT::Other) { + assert(MVT::getSizeInBits(VT) > MVT::getSizeInBits(EVT) && + "Cannot zext to larger type!"); + MVT::ValueType PtrType = N0.getOperand(1).getValueType(); + // For big endian targets, we need to add an offset to the pointer to load + // the correct bytes. For little endian systems, we merely need to read + // fewer bytes from the same pointer. + uint64_t PtrOff = (MVT::getSizeInBits(VT) - MVT::getSizeInBits(EVT)) / 8; + SDOperand NewPtr = TLI.isLittleEndian() ? N0.getOperand(1) : + DAG.getNode(ISD::ADD, PtrType, N0.getOperand(1), + DAG.getConstant(PtrOff, PtrType)); + WorkList.push_back(NewPtr.Val); + SDOperand Load = + DAG.getExtLoad(ISD::ZEXTLOAD, VT, N0.getOperand(0), NewPtr, + N0.getOperand(2), EVT); + WorkList.push_back(N); + CombineTo(N0.Val, Load, Load.getValue(1)); + return SDOperand(); + } + } + return SDOperand(); } _______________________________________________ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits