Skip to content

Commit 1a300f9

Browse files
committed
Set MemoryEffects of call only if called function is nomem
It make call close to constrained calls, where memory effects of the calls do not define memory effects. It helps migration to operand bundles.
1 parent 089909d commit 1a300f9

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

llvm/lib/IR/IRBuilder.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,12 +139,13 @@ CallInst *IRBuilderBase::CreateCall(FunctionType *FTy, Value *Callee,
139139
// If the builder is in strictfp mode and has non-default options (like
140140
// non-dynamic rounding), add corresponding operand bundle. If such bundle is
141141
// already present, assume it overwrites defaults.
142-
bool doesTheCallAccessFPEnv = false;
142+
bool NeedUpdateMemoryEffects = false;
143143
if (IsFPConstrained) {
144144
if (const auto *Func = dyn_cast<Function>(Callee)) {
145145
if (Intrinsic::ID ID = Func->getIntrinsicID()) {
146146
if (IntrinsicInst::isFloatingPointOperation(ID)) {
147-
doesTheCallAccessFPEnv = true;
147+
MemoryEffects FME = Func->getMemoryEffects();
148+
NeedUpdateMemoryEffects = !FME.doesAccessInaccessibleMem();
148149
bool NeedRound = DefaultConstrainedRounding != RoundingMode::Dynamic;
149150
bool NeedExcept = DefaultConstrainedExcept != fp::ebStrict;
150151
for (const auto &Item : OpBundles) {
@@ -166,10 +167,8 @@ CallInst *IRBuilderBase::CreateCall(FunctionType *FTy, Value *Callee,
166167

167168
// If the call accesses FPE, update memory effects accordingly.
168169
CallInst *CI = CallInst::Create(FTy, Callee, Args, OpBundles);
169-
if (doesTheCallAccessFPEnv) {
170+
if (NeedUpdateMemoryEffects) {
170171
MemoryEffects ME = MemoryEffects::inaccessibleMemOnly();
171-
if (CI->getAttributes().hasFnAttr(Attribute::Memory))
172-
ME |= CI->getAttributes().getMemoryEffects();
173172
auto A = Attribute::getWithMemoryEffects(getContext(), ME);
174173
CI->addFnAttr(A);
175174
}

0 commit comments

Comments
 (0)