Skip to content
This repository was archived by the owner on Apr 23, 2020. It is now read-only.

Commit 807111a

Browse files
author
Hal Finkel
committed
[DAGCombine] Remove SIGN_EXTEND-related inf-loop
The patch's author points out that, despite the function's documentation, getSetCCResultType is only used to get the SETCC result type (with one here-removed problematic exception). In one case, getSetCCResultType was being used to get the predicate type to use for a SELECT node, and then SIGN_EXTENDing (or truncating) to get the input predicate to match that type. Unfortunately, this was happening inside visitSIGN_EXTEND, and creating new SIGN_EXTEND nodes was causing an infinite loop. In addition, this behavior was wrong if a target was not using ZeroOrNegativeOneBooleanContent. Lastly, the extension/truncation seems unnecessary here: SELECT is defined as: Select(COND, TRUEVAL, FALSEVAL). If the type of the boolean COND is not i1 then the high bits must conform to getBooleanContents. So here we remove this use of getSetCCResultType and update getSetCCResultType's documentation to reflect its actual uses. Patch by deadal nix! git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@219141 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent b671003 commit 807111a

File tree

3 files changed

+36
-10
lines changed

3 files changed

+36
-10
lines changed

include/llvm/Target/TargetLowering.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -275,10 +275,7 @@ class TargetLoweringBase {
275275
return false;
276276
}
277277

278-
/// Return the ValueType of the result of SETCC operations. Also used to
279-
/// obtain the target's preferred type for the condition operand of SELECT and
280-
/// BRCOND nodes. In the case of BRCOND the argument passed is MVT::Other
281-
/// since there are no other operands to get a type hint from.
278+
/// Return the ValueType of the result of SETCC operations.
282279
virtual EVT getSetCCResultType(LLVMContext &Context, EVT VT) const;
283280

284281
/// Return the ValueType for comparison libcalls. Comparions libcalls include

lib/CodeGen/SelectionDAG/DAGCombiner.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5208,14 +5208,10 @@ SDValue DAGCombiner::visitSIGN_EXTEND(SDNode *N) {
52085208
if (!LegalOperations || TLI.isOperationLegal(ISD::SETCC, SetCCVT)) {
52095209
SDLoc DL(N);
52105210
ISD::CondCode CC = cast<CondCodeSDNode>(N0.getOperand(2))->get();
5211-
SDValue SetCC = DAG.getSetCC(DL,
5212-
SetCCVT,
5211+
SDValue SetCC = DAG.getSetCC(DL, SetCCVT,
52135212
N0.getOperand(0), N0.getOperand(1), CC);
5214-
EVT SelectVT = getSetCCResultType(VT);
5215-
return DAG.getSelect(DL, VT,
5216-
DAG.getSExtOrTrunc(SetCC, DL, SelectVT),
5213+
return DAG.getSelect(DL, VT, SetCC,
52175214
NegOne, DAG.getConstant(0, VT));
5218-
52195215
}
52205216
}
52215217
}

test/CodeGen/X86/sext-i1.ll

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,36 @@ if.end: ; preds = %if.then, %entry
6161
%xor27 = xor i32 undef, %cond ; <i32> [#uses=0]
6262
ret i32 0
6363
}
64+
65+
define i32 @t4(i64 %x) nounwind readnone ssp {
66+
entry:
67+
; 32-LABEL: t4:
68+
; 32: movl
69+
; 32: orl
70+
; 32: movl
71+
; 32: je
72+
; 32: xorl
73+
74+
; 64-LABEL: t4:
75+
; 64: cmpq $1
76+
; 64: sbbl
77+
%0 = icmp eq i64 %x, 0
78+
%1 = sext i1 %0 to i32
79+
ret i32 %1
80+
}
81+
82+
define i64 @t5(i32 %x) nounwind readnone ssp {
83+
entry:
84+
; 32-LABEL: t5:
85+
; 32: cmpl $1
86+
; 32: sbbl
87+
; 32: movl
88+
89+
; 64-LABEL: t5:
90+
; 64: cmpl $1
91+
; 64: sbbq
92+
%0 = icmp eq i32 %x, 0
93+
%1 = sext i1 %0 to i64
94+
ret i64 %1
95+
}
96+

0 commit comments

Comments
 (0)