diff options
author | Chris Lattner <sabre@nondot.org> | 2005-04-07 19:43:53 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2005-04-07 19:43:53 +0000 |
commit | 5a6bace3ab8db44e5412a773626fbb76fb316767 (patch) | |
tree | 4557605c8f9d431218e819d3e2ee8268ffc340f9 /lib/CodeGen | |
parent | cbd06fc3d7511d8dcb64386ffa446f1b20b30ae6 (diff) |
If a target zero or sign extends the result of its setcc, allow folding of
this into sign/zero extension instructions later.
On PPC, for example, this testcase:
%G = external global sbyte
implementation
void %test(int %X, int %Y) {
%C = setlt int %X, %Y
%D = cast bool %C to sbyte
store sbyte %D, sbyte* %G
ret void
}
Now codegens to:
cmpw cr0, r3, r4
li r3, 1
li r4, 0
blt .LBB_test_2 ;
.LBB_test_1: ;
or r3, r4, r4
.LBB_test_2: ;
addis r2, r2, ha16(L_G$non_lazy_ptr-"L00000$pb")
lwz r2, lo16(L_G$non_lazy_ptr-"L00000$pb")(r2)
stb r3, 0(r2)
instead of:
cmpw cr0, r3, r4
li r3, 1
li r4, 0
blt .LBB_test_2 ;
.LBB_test_1: ;
or r3, r4, r4
.LBB_test_2: ;
*** rlwinm r3, r3, 0, 31, 31
addis r2, r2, ha16(L_G$non_lazy_ptr-"L00000$pb")
lwz r2, lo16(L_G$non_lazy_ptr-"L00000$pb")(r2)
stb r3, 0(r2)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21148 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen')
-rw-r--r-- | lib/CodeGen/SelectionDAG/SelectionDAG.cpp | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/lib/CodeGen/SelectionDAG/SelectionDAG.cpp index 7faf19fd72f..04ccc77b6bb 100644 --- a/lib/CodeGen/SelectionDAG/SelectionDAG.cpp +++ b/lib/CodeGen/SelectionDAG/SelectionDAG.cpp @@ -585,7 +585,7 @@ SDOperand SelectionDAG::getNode(unsigned Opcode, MVT::ValueType VT, break; case ISD::ZERO_EXTEND: if (Operand.getValueType() == VT) return Operand; // noop extension - if (OpOpcode == ISD::ZERO_EXTEND) + if (OpOpcode == ISD::ZERO_EXTEND) // (zext (zext x)) -> (zext x) return getNode(ISD::ZERO_EXTEND, VT, Operand.Val->getOperand(0)); break; case ISD::TRUNCATE: @@ -1025,6 +1025,18 @@ SDOperand SelectionDAG::getNode(unsigned Opcode, MVT::ValueType VT,SDOperand N1, return N1; } + // If we are extending the result of a setcc, and we already know the + // contents of the top bits, eliminate the extension. + if (N1.getOpcode() == ISD::SETCC) + switch (TLI.getSetCCResultContents()) { + case TargetLowering::UndefinedSetCCResult: break; + case TargetLowering::ZeroOrOneSetCCResult: + if (Opcode == ISD::ZERO_EXTEND_INREG) return N1; + break; + case TargetLowering::ZeroOrNegativeOneSetCCResult: + if (Opcode == ISD::SIGN_EXTEND_INREG) return N1; + break; + } break; } |