#include "llvm/Analysis/TargetLibraryInfo.h"
namespace llvm {
+class AssumptionCache;
class StringRef;
class Value;
class CallInst;
FortifiedLibCallSimplifier FortifiedSimplifier;
const DataLayout &DL;
const TargetLibraryInfo *TLI;
+ AssumptionCache *AC;
OptimizationRemarkEmitter &ORE;
BlockFrequencyInfo *BFI;
ProfileSummaryInfo *PSI;
public:
LibCallSimplifier(
- const DataLayout &DL, const TargetLibraryInfo *TLI,
- OptimizationRemarkEmitter &ORE,
- BlockFrequencyInfo *BFI, ProfileSummaryInfo *PSI,
+ const DataLayout &DL, const TargetLibraryInfo *TLI, AssumptionCache *AC,
+ OptimizationRemarkEmitter &ORE, BlockFrequencyInfo *BFI,
+ ProfileSummaryInfo *PSI,
function_ref<void(Instruction *, Value *)> Replacer =
&replaceAllUsesWithDefault,
function_ref<void(Instruction *)> Eraser = &eraseFromParentDefault);
// pow(-Inf, 0.5) is optionally required to have a result of +Inf (not setting
// errno), but sqrt(-Inf) is required by various standards to set errno.
if (!Pow->doesNotAccessMemory() && !Pow->hasNoInfs() &&
- !isKnownNeverInfinity(Base, DL, TLI))
+ !isKnownNeverInfinity(Base, DL, TLI, 0, AC, Pow, /*DT=*/nullptr, &ORE))
return nullptr;
Sqrt = getSqrtCall(Base, AttributeList(), Pow->doesNotAccessMemory(), Mod, B,
}
LibCallSimplifier::LibCallSimplifier(
- const DataLayout &DL, const TargetLibraryInfo *TLI,
- OptimizationRemarkEmitter &ORE,
- BlockFrequencyInfo *BFI, ProfileSummaryInfo *PSI,
+ const DataLayout &DL, const TargetLibraryInfo *TLI, AssumptionCache *AC,
+ OptimizationRemarkEmitter &ORE, BlockFrequencyInfo *BFI,
+ ProfileSummaryInfo *PSI,
function_ref<void(Instruction *, Value *)> Replacer,
function_ref<void(Instruction *)> Eraser)
- : FortifiedSimplifier(TLI), DL(DL), TLI(TLI), ORE(ORE), BFI(BFI), PSI(PSI),
- Replacer(Replacer), Eraser(Eraser) {}
+ : FortifiedSimplifier(TLI), DL(DL), TLI(TLI), AC(AC), ORE(ORE), BFI(BFI),
+ PSI(PSI), Replacer(Replacer), Eraser(Eraser) {}
void LibCallSimplifier::replaceAllUsesWith(Instruction *I, Value *With) {
// Indirect through the replacer used in this instance.
declare float @powf(float, float) nounwind readonly
declare float @llvm.pow.f32(float, float)
+declare float @llvm.fabs.f32(float)
declare double @pow(double, double) nounwind readonly
declare double @llvm.pow.f64(double, double)
declare <2 x float> @llvm.pow.v2f32(<2 x float>, <2 x float>) nounwind readonly
declare <2 x double> @llvm.pow.v2f64(<2 x double>, <2 x double>) nounwind readonly
+declare void @llvm.assume(i1 noundef)
; Check pow(1.0, x) -> 1.0.
ret float %retval
}
+; Make sure assume works when inferring no infinities
+define float @powf_libcall_half_assume_ninf(float %x) {
+; ANY-LABEL: define float @powf_libcall_half_assume_ninf
+; ANY-SAME: (float [[X:%.*]]) {
+; ANY-NEXT: [[FABS:%.*]] = call float @llvm.fabs.f32(float [[X]])
+; ANY-NEXT: [[NOT_INF:%.*]] = fcmp one float [[FABS]], 0x7FF0000000000000
+; ANY-NEXT: call void @llvm.assume(i1 [[NOT_INF]])
+; ANY-NEXT: [[SQRTF:%.*]] = call float @sqrtf(float [[X]])
+; ANY-NEXT: [[ABS:%.*]] = call float @llvm.fabs.f32(float [[SQRTF]])
+; ANY-NEXT: [[ISINF:%.*]] = fcmp oeq float [[X]], 0xFFF0000000000000
+; ANY-NEXT: [[RETVAL:%.*]] = select i1 [[ISINF]], float 0x7FF0000000000000, float [[ABS]]
+; ANY-NEXT: ret float [[RETVAL]]
+;
+; VC32-LABEL: define float @powf_libcall_half_assume_ninf
+; VC32-SAME: (float [[X:%.*]]) {
+; VC32-NEXT: [[FABS:%.*]] = call float @llvm.fabs.f32(float [[X]])
+; VC32-NEXT: [[NOT_INF:%.*]] = fcmp one float [[FABS]], 0x7FF0000000000000
+; VC32-NEXT: call void @llvm.assume(i1 [[NOT_INF]])
+; VC32-NEXT: [[RETVAL:%.*]] = call float @powf(float [[X]], float 5.000000e-01)
+; VC32-NEXT: ret float [[RETVAL]]
+;
+; VC51-LABEL: define float @powf_libcall_half_assume_ninf
+; VC51-SAME: (float [[X:%.*]]) {
+; VC51-NEXT: [[FABS:%.*]] = call float @llvm.fabs.f32(float [[X]])
+; VC51-NEXT: [[NOT_INF:%.*]] = fcmp one float [[FABS]], 0x7FF0000000000000
+; VC51-NEXT: call void @llvm.assume(i1 [[NOT_INF]])
+; VC51-NEXT: [[RETVAL:%.*]] = call float @powf(float [[X]], float 5.000000e-01)
+; VC51-NEXT: ret float [[RETVAL]]
+;
+; VC64-LABEL: define float @powf_libcall_half_assume_ninf
+; VC64-SAME: (float [[X:%.*]]) {
+; VC64-NEXT: [[FABS:%.*]] = call float @llvm.fabs.f32(float [[X]])
+; VC64-NEXT: [[NOT_INF:%.*]] = fcmp one float [[FABS]], 0x7FF0000000000000
+; VC64-NEXT: call void @llvm.assume(i1 [[NOT_INF]])
+; VC64-NEXT: [[SQRTF:%.*]] = call float @sqrtf(float [[X]])
+; VC64-NEXT: [[ABS:%.*]] = call float @llvm.fabs.f32(float [[SQRTF]])
+; VC64-NEXT: [[ISINF:%.*]] = fcmp oeq float [[X]], 0xFFF0000000000000
+; VC64-NEXT: [[RETVAL:%.*]] = select i1 [[ISINF]], float 0x7FF0000000000000, float [[ABS]]
+; VC64-NEXT: ret float [[RETVAL]]
+;
+; VC83-LABEL: define float @powf_libcall_half_assume_ninf
+; VC83-SAME: (float [[X:%.*]]) {
+; VC83-NEXT: [[FABS:%.*]] = call float @llvm.fabs.f32(float [[X]])
+; VC83-NEXT: [[NOT_INF:%.*]] = fcmp one float [[FABS]], 0x7FF0000000000000
+; VC83-NEXT: call void @llvm.assume(i1 [[NOT_INF]])
+; VC83-NEXT: [[SQRTF:%.*]] = call float @sqrtf(float [[X]])
+; VC83-NEXT: [[ABS:%.*]] = call float @llvm.fabs.f32(float [[SQRTF]])
+; VC83-NEXT: [[ISINF:%.*]] = fcmp oeq float [[X]], 0xFFF0000000000000
+; VC83-NEXT: [[RETVAL:%.*]] = select i1 [[ISINF]], float 0x7FF0000000000000, float [[ABS]]
+; VC83-NEXT: ret float [[RETVAL]]
+;
+; NOLIB-LABEL: define float @powf_libcall_half_assume_ninf
+; NOLIB-SAME: (float [[X:%.*]]) {
+; NOLIB-NEXT: [[FABS:%.*]] = call float @llvm.fabs.f32(float [[X]])
+; NOLIB-NEXT: [[NOT_INF:%.*]] = fcmp one float [[FABS]], 0x7FF0000000000000
+; NOLIB-NEXT: call void @llvm.assume(i1 [[NOT_INF]])
+; NOLIB-NEXT: [[RETVAL:%.*]] = call float @powf(float [[X]], float 5.000000e-01)
+; NOLIB-NEXT: ret float [[RETVAL]]
+;
+ %fabs = call float @llvm.fabs.f32(float %x)
+ %not.inf = fcmp one float %fabs, 0x7FF0000000000000
+ call void @llvm.assume(i1 %not.inf)
+ %retval = call float @powf(float %x, float 0.5)
+ ret float %retval
+}
+
define float @powf_libcall_half_ninf_tail(float %x) {
; CHECK-LABEL: @powf_libcall_half_ninf_tail(
; ANY-NEXT: %sqrtf = call ninf float @sqrtf(float %x)