[llvm] c8ffc73 - [PartiallyInlineLibCalls] Don't crash when there's a writeonly attribute on the call
Benjamin Kramer via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 5 03:18:59 PST 2022
Author: Benjamin Kramer
Date: 2022-01-05T12:16:26+01:00
New Revision: c8ffc73350dbb6044ca947bbead127b9b914cdf3
URL: https://github.com/llvm/llvm-project/commit/c8ffc73350dbb6044ca947bbead127b9b914cdf3
DIFF: https://github.com/llvm/llvm-project/commit/c8ffc73350dbb6044ca947bbead127b9b914cdf3.diff
LOG: [PartiallyInlineLibCalls] Don't crash when there's a writeonly attribute on the call
readnone subsumes writeonly, so just swap out the attributes. The
verifier doesn't allow us to have both on a call.
Added:
Modified:
llvm/lib/Transforms/Scalar/PartiallyInlineLibCalls.cpp
llvm/test/Transforms/PartiallyInlineLibCalls/X86/good-prototype.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Scalar/PartiallyInlineLibCalls.cpp b/llvm/lib/Transforms/Scalar/PartiallyInlineLibCalls.cpp
index 44027ccd92ca2..e0d0301c1ef62 100644
--- a/llvm/lib/Transforms/Scalar/PartiallyInlineLibCalls.cpp
+++ b/llvm/lib/Transforms/Scalar/PartiallyInlineLibCalls.cpp
@@ -82,6 +82,7 @@ static bool optimizeSQRT(CallInst *Call, Function *CalledFunc,
// Add attribute "readnone" so that backend can use a native sqrt instruction
// for this call.
+ Call->removeFnAttr(Attribute::WriteOnly);
Call->addFnAttr(Attribute::ReadNone);
// Insert a FP compare instruction and use it as the CurrBB branch condition.
diff --git a/llvm/test/Transforms/PartiallyInlineLibCalls/X86/good-prototype.ll b/llvm/test/Transforms/PartiallyInlineLibCalls/X86/good-prototype.ll
index 98aa46219860b..964ce83a36a56 100644
--- a/llvm/test/Transforms/PartiallyInlineLibCalls/X86/good-prototype.ll
+++ b/llvm/test/Transforms/PartiallyInlineLibCalls/X86/good-prototype.ll
@@ -5,7 +5,7 @@
define float @f(float %val) {
; CHECK-LABEL: @f(
; CHECK-NEXT: entry:
-; CHECK-NEXT: [[RES:%.*]] = tail call float @sqrtf(float [[VAL:%.*]]) #0
+; CHECK-NEXT: [[RES:%.*]] = tail call float @sqrtf(float [[VAL:%.*]]) #[[READNONE:.*]]
; CHECK-NEXT: [[TMP0:%.*]] = fcmp oge float [[VAL]], 0.000000e+00
; CHECK-NEXT: br i1 [[TMP0]], label [[ENTRY_SPLIT:%.*]], label [[CALL_SQRT:%.*]]
; CHECK: call.sqrt:
@@ -20,4 +20,16 @@ entry:
ret float %res
}
+define float @f_writeonly(float %val) {
+; CHECK-LABEL: @f_writeonly(
+; CHECK-NEXt: [[RES:%.*]] = tail call float @sqrtf(float [[VAL:%.*]]) #[[READNONE]]
+ %res = tail call float @sqrtf(float %val) writeonly
+ ret float %res
+}
+
+define float @f_readonly(float %val) {
+ %res = tail call float @sqrtf(float %val) readonly
+ ret float %res
+}
+
declare float @sqrtf(float)
More information about the llvm-commits
mailing list