[llvm] 83a5c7c - [ConstantFolding] Ensure TLI is valid when simplifying fp128 intrinsics.
David Green via llvm-commits
llvm-commits at lists.llvm.org
Sat Aug 24 06:39:25 PDT 2024
Author: David Green
Date: 2024-08-24T14:39:20+01:00
New Revision: 83a5c7cb62e404a713a35445b755cf0109650279
URL: https://github.com/llvm/llvm-project/commit/83a5c7cb62e404a713a35445b755cf0109650279
DIFF: https://github.com/llvm/llvm-project/commit/83a5c7cb62e404a713a35445b755cf0109650279.diff
LOG: [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.
Added:
llvm/test/Transforms/Inline/simplify-fp128.ll
Modified:
llvm/lib/Analysis/ConstantFolding.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/ConstantFolding.cpp b/llvm/lib/Analysis/ConstantFolding.cpp
index 81c4d4ec5be412..26d9304cb73672 100644
--- a/llvm/lib/Analysis/ConstantFolding.cpp
+++ b/llvm/lib/Analysis/ConstantFolding.cpp
@@ -2140,7 +2140,7 @@ static Constant *ConstantFoldScalarCall1(StringRef Name,
return GetConstantFoldFPValue128(Result, Ty);
}
LibFunc Fp128Func = NotLibFunc;
- if (TLI->getLibFunc(Name, Fp128Func) && TLI->has(Fp128Func) &&
+ if (TLI && TLI->getLibFunc(Name, Fp128Func) && TLI->has(Fp128Func) &&
Fp128Func == LibFunc_logl)
return ConstantFoldFP128(logf128, Op->getValueAPF(), Ty);
}
diff --git a/llvm/test/Transforms/Inline/simplify-fp128.ll b/llvm/test/Transforms/Inline/simplify-fp128.ll
new file mode 100644
index 00000000000000..73e63702cefcba
--- /dev/null
+++ b/llvm/test/Transforms/Inline/simplify-fp128.ll
@@ -0,0 +1,24 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
+; RUN: opt < %s -passes=inline -S | FileCheck %s
+
+define void @fli() {
+; CHECK-LABEL: define void @fli() {
+; CHECK-NEXT: [[ENTRY:.*:]]
+; CHECK-NEXT: [[TMP0:%.*]] = call fp128 @llvm.floor.f128(fp128 0xL999999999999999A4001199999999999)
+; CHECK-NEXT: ret void
+;
+entry:
+ call void @sc()
+ ret void
+}
+
+define void @sc() {
+; CHECK-LABEL: define void @sc() {
+; CHECK-NEXT: [[ENTRY:.*:]]
+; CHECK-NEXT: [[TMP0:%.*]] = tail call fp128 @llvm.floor.f128(fp128 0xL999999999999999A4001199999999999)
+; CHECK-NEXT: ret void
+;
+entry:
+ %0 = tail call fp128 @llvm.floor.f128(fp128 0xL999999999999999A4001199999999999)
+ ret void
+}
More information about the llvm-commits
mailing list