Skip to content

Commit b5d9a7e

Browse files
Diogo Sampaiozmodem
authored andcommitted
[AArch64][FPenv] Update chain of int to fp conversion
Summary: When using strict fp, it is required to update the chain when performing integer type promotion of a operand to a integer to floating point conversion. Reviewers: craig.topper, john.brawn Reviewed By: craig.topper Subscribers: kristof.beyls, hiraditya, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D74597 (cherry picked from commit 8bc790f)
1 parent cbac419 commit b5d9a7e

File tree

2 files changed

+75
-2
lines changed

2 files changed

+75
-2
lines changed

llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1233,7 +1233,6 @@ bool DAGTypeLegalizer::PromoteIntegerOperand(SDNode *N, unsigned OpNo) {
12331233
LLVM_DEBUG(dbgs() << "Promote integer operand: "; N->dump(&DAG);
12341234
dbgs() << "\n");
12351235
SDValue Res = SDValue();
1236-
12371236
if (CustomLowerNode(N, N->getOperand(OpNo).getValueType(), false)) {
12381237
LLVM_DEBUG(dbgs() << "Node has been custom lowered, done\n");
12391238
return false;
@@ -1330,10 +1329,17 @@ bool DAGTypeLegalizer::PromoteIntegerOperand(SDNode *N, unsigned OpNo) {
13301329
if (Res.getNode() == N)
13311330
return true;
13321331

1333-
assert(Res.getValueType() == N->getValueType(0) && N->getNumValues() == 1 &&
1332+
const bool IsStrictFp = N->isStrictFPOpcode();
1333+
assert(Res.getValueType() == N->getValueType(0) &&
1334+
N->getNumValues() == (IsStrictFp ? 2 : 1) &&
13341335
"Invalid operand expansion");
1336+
LLVM_DEBUG(dbgs() << "Replacing: "; N->dump(&DAG); dbgs() << " with: ";
1337+
Res.dump());
13351338

13361339
ReplaceValueWith(SDValue(N, 0), Res);
1340+
if (IsStrictFp)
1341+
ReplaceValueWith(SDValue(N, 1), SDValue(Res.getNode(), 1));
1342+
13371343
return false;
13381344
}
13391345

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2+
; RUN: llc -O0 -o - %s | FileCheck %s
3+
; RUN: llc -O3 -o - %s | FileCheck %s --check-prefix=SUBOPTIMAL
4+
target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
5+
target triple = "aarch64-arm-none-eabi"
6+
7+
declare float @llvm.experimental.constrained.sitofp.f32.i32(i32, metadata, metadata)
8+
declare float @llvm.experimental.constrained.sitofp.f32.i16(i16, metadata, metadata)
9+
declare i1 @llvm.experimental.constrained.fcmp.f32(float, float, metadata, metadata)
10+
declare float @llvm.experimental.constrained.uitofp.f32.i16(i16, metadata, metadata)
11+
12+
define i32 @test() #0 {
13+
; CHECK-LABEL: test:
14+
; CHECK: // %bb.0: // %entry
15+
; CHECK-NEXT: mov w8, #1
16+
; CHECK-NEXT: scvtf s0, w8
17+
; CHECK-NEXT: fcmp s0, s0
18+
; CHECK-NEXT: cset w0, eq
19+
; CHECK-NEXT: ret
20+
;
21+
; SUBOPTIMAL-LABEL: test:
22+
; SUBOPTIMAL: // %bb.0: // %entry
23+
; SUBOPTIMAL-NEXT: mov w8, #1
24+
; SUBOPTIMAL-NEXT: scvtf s0, w8
25+
; SUBOPTIMAL-NEXT: mov w8, #1
26+
; SUBOPTIMAL-NEXT: scvtf s1, w8
27+
; SUBOPTIMAL-NEXT: fcmp s0, s1
28+
; SUBOPTIMAL-NEXT: cset w8, eq
29+
; SUBOPTIMAL-NEXT: and w0, w8, #0x1
30+
; SUBOPTIMAL-NEXT: ret
31+
entry:
32+
%conv = call float @llvm.experimental.constrained.sitofp.f32.i32(i32 1, metadata !"round.tonearest", metadata !"fpexcept.strict")
33+
%conv1 = call float @llvm.experimental.constrained.sitofp.f32.i16(i16 1, metadata !"round.tonearest", metadata !"fpexcept.strict")
34+
%cmp = call i1 @llvm.experimental.constrained.fcmp.f32(float %conv, float %conv1, metadata !"oeq", metadata !"fpexcept.strict")
35+
%conv2 = zext i1 %cmp to i32
36+
ret i32 %conv2
37+
}
38+
39+
define i32 @test2() #0 {
40+
; CHECK-LABEL: test2:
41+
; CHECK: // %bb.0: // %entry
42+
; CHECK-NEXT: mov w8, #1
43+
; CHECK-NEXT: scvtf s0, w8
44+
; CHECK-NEXT: ucvtf s1, w8
45+
; CHECK-NEXT: fcmp s0, s1
46+
; CHECK-NEXT: cset w0, eq
47+
; CHECK-NEXT: ret
48+
;
49+
; SUBOPTIMAL-LABEL: test2:
50+
; SUBOPTIMAL: // %bb.0: // %entry
51+
; SUBOPTIMAL-NEXT: mov w8, #1
52+
; SUBOPTIMAL-NEXT: scvtf s0, w8
53+
; SUBOPTIMAL-NEXT: mov w8, #1
54+
; SUBOPTIMAL-NEXT: ucvtf s1, w8
55+
; SUBOPTIMAL-NEXT: fcmp s0, s1
56+
; SUBOPTIMAL-NEXT: cset w8, eq
57+
; SUBOPTIMAL-NEXT: and w0, w8, #0x1
58+
; SUBOPTIMAL-NEXT: ret
59+
entry:
60+
%conv = call float @llvm.experimental.constrained.sitofp.f32.i32(i32 1, metadata !"round.tonearest", metadata !"fpexcept.strict")
61+
%conv1 = call float @llvm.experimental.constrained.uitofp.f32.i16(i16 1, metadata !"round.tonearest", metadata !"fpexcept.strict")
62+
%cmp = call i1 @llvm.experimental.constrained.fcmp.f32(float %conv, float %conv1, metadata !"oeq", metadata !"fpexcept.strict")
63+
%conv2 = zext i1 %cmp to i32
64+
ret i32 %conv2
65+
}
66+
67+
attributes #0 = { noinline optnone }

0 commit comments

Comments
 (0)