Skip to content

Commit 6c7c406

Browse files
author
git apple-llvm automerger
committed
Merge commit 'f49d2dca4de9' from swift/release/5.3 into swift/master
2 parents e0fb144 + f49d2dc commit 6c7c406

File tree

2 files changed

+82
-3
lines changed

2 files changed

+82
-3
lines changed

llvm/lib/Target/AArch64/AArch64PromoteConstant.cpp

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,20 @@ static bool isConstantUsingVectorTy(const Type *CstTy) {
250250
return false;
251251
}
252252

253+
// Returns true if \p C contains only ConstantData leafs and no global values,
254+
// block addresses or constant expressions. Traverses ConstantAggregates.
255+
static bool containsOnlyConstantData(const Constant *C) {
256+
if (isa<ConstantData>(C))
257+
return true;
258+
259+
if (isa<GlobalValue>(C) || isa<BlockAddress>(C) || isa<ConstantExpr>(C))
260+
return false;
261+
262+
return all_of(C->operands(), [](const Use &U) {
263+
return containsOnlyConstantData(cast<Constant>(&U));
264+
});
265+
}
266+
253267
/// Check if the given use (Instruction + OpIdx) of Cst should be converted into
254268
/// a load of a global variable initialized with Cst.
255269
/// A use should be converted if it is legal to do so.
@@ -550,9 +564,10 @@ bool AArch64PromoteConstant::runOnFunction(Function &F,
550564
for (Use &U : I.operands()) {
551565
Constant *Cst = dyn_cast<Constant>(U);
552566
// There is no point in promoting global values as they are already
553-
// global. Do not promote constant expressions either, as they may
554-
// require some code expansion.
555-
if (!Cst || isa<GlobalValue>(Cst) || isa<ConstantExpr>(Cst))
567+
// global. Do not promote constants containing constant expression, global
568+
// values or blockaddresses either, as they may require some code
569+
// expansion.
570+
if (!Cst || isa<GlobalValue>(Cst) || !containsOnlyConstantData(Cst))
556571
continue;
557572

558573
// Check if this constant is worth promoting.
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
; RUN: llc -o - %s | FileCheck %s
2+
3+
; AsmPrinter cannot lower floating point constant expressions in global
4+
; initializers. Check that we do not create new globals with float constant
5+
; expressions in initializers.
6+
7+
target datalayout = "e-m:o-i64:64-i128:128-n32:64-S128"
8+
target triple = "arm64-apple-ios14.0.0"
9+
10+
define [1 x <4 x float>] @test1() {
11+
; CHECK-LABEL: .p2align 4 ; -- Begin function test1
12+
; CHECK-NEXT: lCPI0_0:
13+
; CHECK-NEXT: .quad 0 ; 0x0
14+
; CHECK-NEXT: .quad 4575657221408423936 ; 0x3f80000000000000
15+
; CHECK-NEXT: .section __TEXT,__text,regular,pure_instructions
16+
; CHECK-NEXT: .globl _test1
17+
; CHECK-NEXT: .p2align 2
18+
; CHECK-NEXT: _test1: ; @test1
19+
; CHECK-NEXT: .cfi_startproc
20+
; CHECK-NEXT: ; %bb.0:
21+
; CHECK-NEXT: Lloh0:
22+
; CHECK-NEXT: adrp x8, lCPI0_0@PAGE
23+
; CHECK-NEXT: Lloh1:
24+
; CHECK-NEXT: ldr q0, [x8, lCPI0_0@PAGEOFF]
25+
; CHECK-NEXT: ret
26+
27+
ret [1 x <4 x float>] [<4 x float> bitcast (<1 x i128> <i128 84405977732342157929391748327801880576> to <4 x float>)]
28+
}
29+
30+
define [1 x <4 x float>] @test2() {
31+
; CHECK-LABEL: .p2align 4 ; -- Begin function test2
32+
; CHECK-NEXT: lCPI1_0:
33+
; CHECK-NEXT: .long 0 ; float 0
34+
; CHECK-NEXT: .long 0 ; float 0
35+
; CHECK-NEXT: .long 0 ; float 0
36+
; CHECK-NEXT: .long 1065353216 ; float 1
37+
; CHECK-NEXT: .section __TEXT,__text,regular,pure_instructions
38+
; CHECK-NEXT: .globl _test2
39+
; CHECK-NEXT: .p2align 2
40+
; CHECK-NEXT: _test2: ; @test2
41+
; CHECK-NEXT: .cfi_startproc
42+
; CHECK-NEXT: ; %bb.0:
43+
; CHECK-NEXT: Lloh2:
44+
; CHECK-NEXT: adrp x8, lCPI1_0@PAGE
45+
; CHECK-NEXT: Lloh3:
46+
; CHECK-NEXT: ldr q1, [x8, lCPI1_0@PAGEOFF]
47+
; CHECK-NEXT: mov s2, v1[1]
48+
; CHECK-NEXT: fneg s0, s1
49+
; CHECK-NEXT: mov s3, v1[2]
50+
; CHECK-NEXT: fneg s2, s2
51+
; CHECK-NEXT: mov s1, v1[3]
52+
; CHECK-NEXT: fneg s3, s3
53+
; CHECK-NEXT: mov.s v0[1], v2[0]
54+
; CHECK-NEXT: mov.s v0[2], v3[0]
55+
; CHECK-NEXT: fneg s1, s1
56+
; CHECK-NEXT: mov.s v0[3], v1[0]
57+
; CHECK-NEXT: ret
58+
;
59+
ret [1 x <4 x float>] [<4 x float>
60+
<float fneg (float extractelement (<4 x float> bitcast (<1 x i128> <i128 84405977732342157929391748327801880576> to <4 x float>), i32 0)),
61+
float fneg (float extractelement (<4 x float> bitcast (<1 x i128> <i128 84405977732342157929391748327801880576> to <4 x float>), i32 1)),
62+
float fneg (float extractelement (<4 x float> bitcast (<1 x i128> <i128 84405977732342157929391748327801880576> to <4 x float>), i32 2)),
63+
float fneg (float extractelement (<4 x float> bitcast (<1 x i128> <i128 84405977732342157929391748327801880576> to <4 x float>), i32 3))>]
64+
}

0 commit comments

Comments
 (0)