Skip to content

Commit

Permalink
Revert "[InferAttrs] Add writeonly to all the math functions"
Browse files Browse the repository at this point in the history
This reverts commit ea75be3 and
1eb5b6e.

That commit caused crashes with compilation e.g. like this
(not fixed by the follow-up commit):

$ cat sqrt.c
float a;
b() { sqrt(a); }
$ clang -target x86_64-linux-gnu -c -O2 sqrt.c
Attributes 'readnone and writeonly' are incompatible!
  %sqrtf = tail call float @sqrtf(float %0) #1
in function b
fatal error: error in backend: Broken function found, compilation aborted!
  • Loading branch information
mstorsjo committed Jan 5, 2022
1 parent 30d7396 commit 29b6e96
Show file tree
Hide file tree
Showing 2 changed files with 116 additions and 133 deletions.
15 changes: 0 additions & 15 deletions llvm/lib/Transforms/Utils/BuildLibCalls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ STATISTIC(NumReadNone, "Number of functions inferred as readnone");
STATISTIC(NumInaccessibleMemOnly,
"Number of functions inferred as inaccessiblememonly");
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(NumInaccessibleMemOrArgMemOnly,
"Number of functions inferred as inaccessiblemem_or_argmemonly");
Expand Down Expand Up @@ -72,19 +71,6 @@ static bool setOnlyReadsMemory(Function &F) {
return true;
}

static bool setDoesNotReadMemory(Function &F) {
if (F.doesNotReadMemory()) // writeonly or readnone
return false;
++NumWriteOnly;
if (F.hasFnAttribute(Attribute::ReadOnly)) {
F.removeFnAttr(Attribute::ReadOnly);
F.setDoesNotAccessMemory();
} else {
F.setDoesNotReadMemory();
}
return true;
}

static bool setOnlyAccessesArgMemory(Function &F) {
if (F.onlyAccessesArgMemory())
return false;
Expand Down Expand Up @@ -1185,7 +1171,6 @@ bool llvm::inferLibFuncAttributes(Function &F, const TargetLibraryInfo &TLI) {
case LibFunc_truncl:
Changed |= setDoesNotThrow(F);
Changed |= setDoesNotFreeMemory(F);
Changed |= setDoesNotReadMemory(F);
Changed |= setWillReturn(F);
return Changed;
default:
Expand Down
Loading

0 comments on commit 29b6e96

Please sign in to comment.