[llvm-commits] [llvm] r57247 - /llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
Dan Gohman
gohman at apple.com
Tue Oct 7 10:53:57 PDT 2008
On Tue, October 7, 2008 10:03 am, Andrew Lenharth wrote:
> Author: alenhar2
> Date: Tue Oct 7 12:03:15 2008
> New Revision: 57247
>
> URL: http://llvm.org/viewvc/llvm-project?rev=57247&view=rev
> Log:
> Use ADDC if it is valid at any smaller size. fixes
> test/Codegen/Generic/i128-addsub.ll on x86
>
> Modified:
> llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
>
> Modified: llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp?rev=57247&r1=57246&r2=57247&view=diff
>
> ==============================================================================
> --- llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp (original)
> +++ llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp Tue Oct 7
> 12:03:15 2008
> @@ -6441,7 +6441,20 @@
> LoOps[1] = RHSL;
> HiOps[0] = LHSH;
> HiOps[1] = RHSH;
> - if(TLI.isOperationLegal(ISD::ADDC, NVT)) {
> + //cascaded check to see if any smaller size has a a carry flag.
> + unsigned OpV = Node->getOpcode() == ISD::ADD ? ISD::ADDC : ISD::SUBC;
> + bool hasCarry = false;
> + if (NVT == MVT::i64)
> + hasCarry |= TLI.isOperationLegal(OpV, MVT::i32)
> + | TLI.isOperationLegal(OpV, MVT::i16)
> + | TLI.isOperationLegal(OpV, MVT::i8);
> + if (NVT == MVT::i32)
> + hasCarry |= TLI.isOperationLegal(OpV, MVT::i16)
> + | TLI.isOperationLegal(OpV, MVT::i8);
> + if (NVT == MVT::i16)
> + hasCarry |= TLI.isOperationLegal(OpV, MVT::i8);
Previously, it was possible to do an i256 add on x86. I guess we
don't have any testcases for that in the repository though.
How about a more general approach? Warning untested code:
bool hasCarry = false;
for (unsigned BitSize = NVT.getSizeInBits(); BitSize != 0; BitSize /= 2) {
MVT AVT = MVT::getIntegerVT(BitSize);
if (TLI.isOperationLegal(OpV, AVT)) {
hasCarry = true;
break;
}
}
FWIW, LegalizeIntegerTypes.cpp will eventually need to do
something similar, and it'll need to account for non-power-of-two
integer sizes also.
Dan
More information about the llvm-commits
mailing list