Skip to content

Commit 79f56c9

Browse files
committed
Fix a compiler crash where a Glue value had multiple uses. Radar 9049552.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@127198 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 1b772f9 commit 79f56c9

File tree

3 files changed

+46
-1
lines changed

3 files changed

+46
-1
lines changed

lib/Target/ARM/ARMISelLowering.cpp

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2527,6 +2527,27 @@ ARMTargetLowering::getVFPCmp(SDValue LHS, SDValue RHS, SelectionDAG &DAG,
25272527
return DAG.getNode(ARMISD::FMSTAT, dl, MVT::Glue, Cmp);
25282528
}
25292529

2530+
/// duplicateCmp - Glue values can have only one use, so this function
2531+
/// duplicates a comparison node.
2532+
SDValue
2533+
ARMTargetLowering::duplicateCmp(SDValue Cmp, SelectionDAG &DAG) const {
2534+
unsigned Opc = Cmp.getOpcode();
2535+
DebugLoc DL = Cmp.getDebugLoc();
2536+
if (Opc == ARMISD::CMP || Opc == ARMISD::CMPZ)
2537+
return DAG.getNode(Opc, DL, MVT::Glue, Cmp.getOperand(0),Cmp.getOperand(1));
2538+
2539+
assert(Opc == ARMISD::FMSTAT && "unexpected comparison operation");
2540+
Cmp = Cmp.getOperand(0);
2541+
Opc = Cmp.getOpcode();
2542+
if (Opc == ARMISD::CMPFP)
2543+
Cmp = DAG.getNode(Opc, DL, MVT::Glue, Cmp.getOperand(0),Cmp.getOperand(1));
2544+
else {
2545+
assert(Opc == ARMISD::CMPFPw0 && "unexpected operand of FMSTAT");
2546+
Cmp = DAG.getNode(Opc, DL, MVT::Glue, Cmp.getOperand(0));
2547+
}
2548+
return DAG.getNode(ARMISD::FMSTAT, DL, MVT::Glue, Cmp);
2549+
}
2550+
25302551
SDValue ARMTargetLowering::LowerSELECT(SDValue Op, SelectionDAG &DAG) const {
25312552
SDValue Cond = Op.getOperand(0);
25322553
SDValue SelectTrue = Op.getOperand(1);
@@ -2562,7 +2583,7 @@ SDValue ARMTargetLowering::LowerSELECT(SDValue Op, SelectionDAG &DAG) const {
25622583
EVT VT = Cond.getValueType();
25632584
SDValue ARMcc = Cond.getOperand(2);
25642585
SDValue CCR = Cond.getOperand(3);
2565-
SDValue Cmp = Cond.getOperand(4);
2586+
SDValue Cmp = duplicateCmp(Cond.getOperand(4), DAG);
25662587
return DAG.getNode(ARMISD::CMOV, dl, VT, True, False, ARMcc, CCR, Cmp);
25672588
}
25682589
}

lib/Target/ARM/ARMISelLowering.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,7 @@ namespace llvm {
459459
SDValue &ARMcc, SelectionDAG &DAG, DebugLoc dl) const;
460460
SDValue getVFPCmp(SDValue LHS, SDValue RHS,
461461
SelectionDAG &DAG, DebugLoc dl) const;
462+
SDValue duplicateCmp(SDValue Cmp, SelectionDAG &DAG) const;
462463

463464
SDValue OptimizeVFPBrcond(SDValue Op, SelectionDAG &DAG) const;
464465

test/CodeGen/ARM/select.ll

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,26 @@ define arm_apcscc float @f8(i32 %a) nounwind {
9090
%tmp1 = select i1 %tmp, float 0x3FF3BE76C0000000, float 0x40030E9A20000000
9191
ret float %tmp1
9292
}
93+
94+
; <rdar://problem/9049552>
95+
; Glue values can only have a single use, but the following test exposed a
96+
; case where a SELECT was lowered with 2 uses of a comparison, causing the
97+
; scheduler to assert.
98+
; CHECK-VFP: f9:
99+
100+
declare i8* @objc_msgSend(i8*, i8*, ...)
101+
define void @f9() optsize {
102+
entry:
103+
%cmp = icmp eq i8* undef, inttoptr (i32 4 to i8*)
104+
%conv191 = select i1 %cmp, float -3.000000e+00, float 0.000000e+00
105+
%conv195 = select i1 %cmp, double -1.000000e+00, double 0.000000e+00
106+
%add = fadd double %conv195, 1.100000e+01
107+
%conv196 = fptrunc double %add to float
108+
%add201 = fadd float undef, %conv191
109+
%tmp484 = bitcast float %conv196 to i32
110+
%tmp478 = bitcast float %add201 to i32
111+
%tmp490 = insertvalue [2 x i32] undef, i32 %tmp484, 0
112+
%tmp493 = insertvalue [2 x i32] %tmp490, i32 %tmp478, 1
113+
call void bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to void (i8*, i8*, [2 x i32], i32, float)*)(i8* undef, i8* undef, [2 x i32] %tmp493, i32 0, float 1.000000e+00) optsize
114+
ret void
115+
}

0 commit comments

Comments
 (0)