Skip to content

Commit 83a5c7c

Browse files
committed
[ConstantFolding] Ensure TLI is valid when simplifying fp128 intrinsics.
TLI might not be valid for all contexts that constant folding is performed. Add a quick guard that it is not null.
1 parent 40975da commit 83a5c7c

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

llvm/lib/Analysis/ConstantFolding.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2140,7 +2140,7 @@ static Constant *ConstantFoldScalarCall1(StringRef Name,
21402140
return GetConstantFoldFPValue128(Result, Ty);
21412141
}
21422142
LibFunc Fp128Func = NotLibFunc;
2143-
if (TLI->getLibFunc(Name, Fp128Func) && TLI->has(Fp128Func) &&
2143+
if (TLI && TLI->getLibFunc(Name, Fp128Func) && TLI->has(Fp128Func) &&
21442144
Fp128Func == LibFunc_logl)
21452145
return ConstantFoldFP128(logf128, Op->getValueAPF(), Ty);
21462146
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
2+
; RUN: opt < %s -passes=inline -S | FileCheck %s
3+
4+
define void @fli() {
5+
; CHECK-LABEL: define void @fli() {
6+
; CHECK-NEXT: [[ENTRY:.*:]]
7+
; CHECK-NEXT: [[TMP0:%.*]] = call fp128 @llvm.floor.f128(fp128 0xL999999999999999A4001199999999999)
8+
; CHECK-NEXT: ret void
9+
;
10+
entry:
11+
call void @sc()
12+
ret void
13+
}
14+
15+
define void @sc() {
16+
; CHECK-LABEL: define void @sc() {
17+
; CHECK-NEXT: [[ENTRY:.*:]]
18+
; CHECK-NEXT: [[TMP0:%.*]] = tail call fp128 @llvm.floor.f128(fp128 0xL999999999999999A4001199999999999)
19+
; CHECK-NEXT: ret void
20+
;
21+
entry:
22+
%0 = tail call fp128 @llvm.floor.f128(fp128 0xL999999999999999A4001199999999999)
23+
ret void
24+
}

0 commit comments

Comments
 (0)