Skip to content

Commit 0ece205

Browse files
committed
[SystemZ] Implement isGuaranteedNotToBeUndefOrPoisonForTargetNode().
Returning true from this method for PCREL_WRAPPER and PCREL_OFFSET avoids problems when a PCREL_OFFSET node ends up with a freeze operand, which is not handled or expected by the backend. Fixes #60107 Reviewed By: uweigand, RKSimon Differential Revision: https://reviews.llvm.org/D142971
1 parent 67b7120 commit 0ece205

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed

llvm/lib/Target/SystemZ/SystemZISelLowering.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7443,6 +7443,18 @@ SystemZTargetLowering::ComputeNumSignBitsForTargetNode(
74437443
return 1;
74447444
}
74457445

7446+
bool SystemZTargetLowering::
7447+
isGuaranteedNotToBeUndefOrPoisonForTargetNode(SDValue Op,
7448+
const APInt &DemandedElts, const SelectionDAG &DAG,
7449+
bool PoisonOnly, unsigned Depth) const {
7450+
switch (Op->getOpcode()) {
7451+
case SystemZISD::PCREL_WRAPPER:
7452+
case SystemZISD::PCREL_OFFSET:
7453+
return true;
7454+
}
7455+
return false;
7456+
}
7457+
74467458
unsigned
74477459
SystemZTargetLowering::getStackProbeSize(const MachineFunction &MF) const {
74487460
const TargetFrameLowering *TFI = Subtarget.getFrameLowering();

llvm/lib/Target/SystemZ/SystemZISelLowering.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,10 @@ class SystemZTargetLowering : public TargetLowering {
600600
const SelectionDAG &DAG,
601601
unsigned Depth) const override;
602602

603+
bool isGuaranteedNotToBeUndefOrPoisonForTargetNode(
604+
SDValue Op, const APInt &DemandedElts, const SelectionDAG &DAG,
605+
bool PoisonOnly, unsigned Depth) const override;
606+
603607
ISD::NodeType getExtendForAtomicOps() const override {
604608
return ISD::ANY_EXTEND;
605609
}

llvm/test/CodeGen/SystemZ/freeze.ll

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
; RUN: llc -mtriple=s390x-linux-gnu -mcpu=zEC12 < %s | FileCheck %s
2+
;
3+
; Check that DAGCombiner doesn't cause a crash by eventually producing a
4+
; PCREL_OFFSET node with a freeze operand.
5+
6+
@a = dso_local global [6 x [6 x [3 x i8]]] zeroinitializer, align 2
7+
@b = dso_local local_unnamed_addr global i32 0, align 4
8+
9+
define void @fun(i8 noundef zeroext %g) {
10+
; CHECK-LABEL: fun
11+
entry:
12+
%agg.tmp.ensured.sroa.0 = alloca i8, align 2
13+
%conv = zext i8 %g to i64
14+
%0 = inttoptr i64 %conv to ptr
15+
%.fr = freeze ptr getelementptr inbounds ([6 x [6 x [3 x i8]]], ptr @a, i64 0, i64 1, i64 2, i64 1)
16+
%cmp = icmp eq ptr %.fr, %0
17+
%1 = load i8, ptr getelementptr inbounds ([6 x [6 x [3 x i8]]], ptr @a, i64 0, i64 5, i64 4, i64 2), align 2
18+
%conv2 = zext i8 %1 to i32
19+
br i1 %cmp, label %for.cond.us, label %for.cond
20+
21+
for.cond.us: ; preds = %entry, %for.cond.us
22+
store i32 %conv2, ptr @b, align 4
23+
ret void
24+
25+
for.cond: ; preds = %entry, %for.cond
26+
store i32 0, ptr @b, align 4
27+
ret void
28+
}

0 commit comments

Comments
 (0)