-
Notifications
You must be signed in to change notification settings - Fork 15.3k
[InferAttrs] Mark floating-point libcalls as errno-writing #124742
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
antoniofrighetto
merged 1 commit into
llvm:main
from
antoniofrighetto:feature/infer-errnomem-libcalls
Mar 13, 2025
+227
−189
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -39,8 +39,13 @@ STATISTIC(NumInaccessibleMemOnly, | |
| STATISTIC(NumReadOnly, "Number of functions inferred as readonly"); | ||
| STATISTIC(NumWriteOnly, "Number of functions inferred as writeonly"); | ||
| STATISTIC(NumArgMemOnly, "Number of functions inferred as argmemonly"); | ||
| STATISTIC(NumWriteErrnoMemOnly, | ||
| "Number of functions inferred as memory(errnomem: write)"); | ||
| STATISTIC(NumInaccessibleMemOrArgMemOnly, | ||
| "Number of functions inferred as inaccessiblemem_or_argmemonly"); | ||
| STATISTIC( | ||
| NumWriteArgumentMemOrErrnoMemOnly, | ||
| "Number of functions inferred as memory(argmem: write, errnomem: write)"); | ||
| STATISTIC(NumNoUnwind, "Number of functions inferred as nounwind"); | ||
| STATISTIC(NumNoCapture, "Number of arguments inferred as nocapture"); | ||
| STATISTIC(NumWriteOnlyArg, "Number of arguments inferred as writeonly"); | ||
|
|
@@ -120,6 +125,21 @@ static bool setOnlyAccessesInaccessibleMemOrArgMem(Function &F) { | |
| return true; | ||
| } | ||
|
|
||
| static bool setOnlyWritesErrnoMemory(Function &F) { | ||
| if (!setMemoryEffects(F, MemoryEffects::errnoMemOnly(ModRefInfo::Mod))) | ||
| return false; | ||
| ++NumWriteErrnoMemOnly; | ||
| return true; | ||
| } | ||
|
|
||
| static bool setOnlyWritesArgMemOrErrnoMem(Function &F) { | ||
| if (!setMemoryEffects(F, MemoryEffects::argumentOrErrnoMemOnly( | ||
| ModRefInfo::Mod, ModRefInfo::Mod))) | ||
| return false; | ||
| ++NumWriteArgumentMemOrErrnoMemOnly; | ||
| return true; | ||
| } | ||
|
|
||
| static bool setDoesNotThrow(Function &F) { | ||
| if (F.doesNotThrow()) | ||
| return false; | ||
|
|
@@ -1149,14 +1169,9 @@ bool llvm::inferNonMandatoryLibFuncAttrs(Function &F, | |
| case LibFunc_ldexp: | ||
| case LibFunc_ldexpf: | ||
| case LibFunc_ldexpl: | ||
| Changed |= setOnlyWritesErrnoMemory(F); | ||
| Changed |= setWillReturn(F); | ||
| break; | ||
| case LibFunc_remquo: | ||
| case LibFunc_remquof: | ||
| case LibFunc_remquol: | ||
| Changed |= setDoesNotCapture(F, 2); | ||
| [[fallthrough]]; | ||
| case LibFunc_abs: | ||
| case LibFunc_acos: | ||
| case LibFunc_acosf: | ||
| case LibFunc_acosh: | ||
|
|
@@ -1178,15 +1193,9 @@ bool llvm::inferNonMandatoryLibFuncAttrs(Function &F, | |
| case LibFunc_atanhf: | ||
| case LibFunc_atanhl: | ||
| case LibFunc_atanl: | ||
| case LibFunc_cbrt: | ||
| case LibFunc_cbrtf: | ||
| case LibFunc_cbrtl: | ||
| case LibFunc_ceil: | ||
| case LibFunc_ceilf: | ||
| case LibFunc_ceill: | ||
| case LibFunc_copysign: | ||
| case LibFunc_copysignf: | ||
| case LibFunc_copysignl: | ||
| case LibFunc_cos: | ||
| case LibFunc_cosh: | ||
| case LibFunc_coshf: | ||
|
|
@@ -1210,37 +1219,15 @@ bool llvm::inferNonMandatoryLibFuncAttrs(Function &F, | |
| case LibFunc_expm1: | ||
| case LibFunc_expm1f: | ||
| case LibFunc_expm1l: | ||
| case LibFunc_fabs: | ||
| case LibFunc_fabsf: | ||
| case LibFunc_fabsl: | ||
| case LibFunc_fdim: | ||
| case LibFunc_fdiml: | ||
| case LibFunc_fdimf: | ||
| case LibFunc_ffs: | ||
| case LibFunc_ffsl: | ||
| case LibFunc_ffsll: | ||
| case LibFunc_floor: | ||
| case LibFunc_floorf: | ||
| case LibFunc_floorl: | ||
| case LibFunc_fls: | ||
| case LibFunc_flsl: | ||
| case LibFunc_flsll: | ||
| case LibFunc_fmax: | ||
| case LibFunc_fmaxf: | ||
| case LibFunc_fmaxl: | ||
| case LibFunc_fmin: | ||
| case LibFunc_fminf: | ||
| case LibFunc_fminl: | ||
| case LibFunc_fmod: | ||
| case LibFunc_fmodf: | ||
| case LibFunc_fmodl: | ||
| case LibFunc_hypot: | ||
| case LibFunc_hypotf: | ||
| case LibFunc_hypotl: | ||
| case LibFunc_isascii: | ||
| case LibFunc_isdigit: | ||
| case LibFunc_labs: | ||
| case LibFunc_llabs: | ||
| case LibFunc_log: | ||
| case LibFunc_log10: | ||
| case LibFunc_log10f: | ||
|
|
@@ -1259,9 +1246,6 @@ bool llvm::inferNonMandatoryLibFuncAttrs(Function &F, | |
| case LibFunc_ilogbl: | ||
| case LibFunc_logf: | ||
| case LibFunc_logl: | ||
| case LibFunc_nearbyint: | ||
| case LibFunc_nearbyintf: | ||
| case LibFunc_nearbyintl: | ||
| case LibFunc_pow: | ||
| case LibFunc_powf: | ||
| case LibFunc_powl: | ||
|
|
@@ -1298,26 +1282,68 @@ bool llvm::inferNonMandatoryLibFuncAttrs(Function &F, | |
| case LibFunc_tanhf: | ||
| case LibFunc_tanhl: | ||
| case LibFunc_tanl: | ||
| Changed |= setDoesNotThrow(F); | ||
| Changed |= setDoesNotFreeMemory(F); | ||
| Changed |= setWillReturn(F); | ||
| Changed |= setOnlyWritesErrnoMemory(F); | ||
| break; | ||
| case LibFunc_abs: | ||
| case LibFunc_cbrt: | ||
| case LibFunc_cbrtf: | ||
| case LibFunc_cbrtl: | ||
| case LibFunc_copysign: | ||
| case LibFunc_copysignf: | ||
| case LibFunc_copysignl: | ||
| case LibFunc_fabs: | ||
| case LibFunc_fabsf: | ||
| case LibFunc_fabsl: | ||
| case LibFunc_ffs: | ||
| case LibFunc_ffsl: | ||
| case LibFunc_ffsll: | ||
| case LibFunc_floor: | ||
| case LibFunc_floorf: | ||
| case LibFunc_floorl: | ||
| case LibFunc_fls: | ||
| case LibFunc_flsl: | ||
| case LibFunc_flsll: | ||
| case LibFunc_fmax: | ||
| case LibFunc_fmaxf: | ||
| case LibFunc_fmaxl: | ||
| case LibFunc_fmin: | ||
| case LibFunc_fminf: | ||
| case LibFunc_fminl: | ||
| case LibFunc_labs: | ||
| case LibFunc_llabs: | ||
|
||
| case LibFunc_nearbyint: | ||
| case LibFunc_nearbyintf: | ||
| case LibFunc_nearbyintl: | ||
| case LibFunc_toascii: | ||
| case LibFunc_trunc: | ||
| case LibFunc_truncf: | ||
| case LibFunc_truncl: | ||
| Changed |= setDoesNotAccessMemory(F); | ||
| [[fallthrough]]; | ||
| case LibFunc_isascii: | ||
| case LibFunc_isdigit: | ||
| Changed |= setDoesNotThrow(F); | ||
| Changed |= setDoesNotFreeMemory(F); | ||
| Changed |= setOnlyWritesMemory(F); | ||
| Changed |= setWillReturn(F); | ||
| break; | ||
| case LibFunc_sincos: | ||
| case LibFunc_sincosf: | ||
| case LibFunc_sincosl: | ||
| Changed |= setDoesNotCapture(F, 1); | ||
| Changed |= setOnlyWritesMemory(F, 1); | ||
| [[fallthrough]]; | ||
| case LibFunc_remquo: | ||
| case LibFunc_remquof: | ||
| case LibFunc_remquol: | ||
| Changed |= setDoesNotThrow(F); | ||
| Changed |= setDoesNotFreeMemory(F); | ||
| Changed |= setOnlyWritesMemory(F); | ||
| Changed |= setOnlyWritesMemory(F, 1); | ||
| Changed |= setOnlyWritesMemory(F, 2); | ||
| Changed |= setDoesNotCapture(F, 1); | ||
| Changed |= setDoesNotCapture(F, 2); | ||
| Changed |= setWillReturn(F); | ||
| Changed |= setOnlyWritesArgMemOrErrnoMem(F); | ||
| break; | ||
| default: | ||
| // FIXME: It'd be really nice to cover all the library functions we're | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can merge ldexp with the rest of the FP libcall list? Should also be able to set doesNotThrow and setDoesNotFreeMemory on it...