← Back to Pull requests

[IR] Memory locations for floating-point operations #226826

Open
spavloff opened this pull request with 401 lines diff across 24 files
View on GitHub
spavloff spavloff commented on Sep 27, 2026 19:11 UTC
Author

Floating-point operations in a strictfp function have side effects, which are modeled using memory effects in the form of a read-write access to "inaccessible memory". This helps maintain strictfp semantics but may hinder optimizations. Floating-point operations may depend on rounding mode or not - this fact may be used to reorder them in a more optimal way. Similarly, functions that control floating-point environment (like set_rounding, set_fpmode etc.) also have more specific access than generic read-write. Also, "inaccessible memory" is used in cases other than FP operation, this results in unnecessary restrictions.

This change implements two new memory location to use instead of the access to "inaccessible memory". The "fpcontrol" location is used to represent access to floating-point control modes, of which only rounding mode is currently supported. The other location, "fpstatus", represents access to floating-point exceptions. Together they replace the use of "inaccessible memory".

This change only introduces the new memory locations. Their use in the functions that access the floating-point environment will be implemented in another commit.

This MR was obtained from
https://github.com/llvm/llvm-project/pull/221754 by keeping only the changes required to introduce the new memory locations only.

Diff: 401 lines (+316 / -85) across 24 files Reviewer: CarolineConcatto Review duration: 92970m
All Vouch review confidence checks passed
Residual risk 0.08 = Change Risk (0.74) × (1 − Review Confidence (0.90)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.74 · 401 lines diff across 24 files
0.74
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.92 · 5 substantive comment(s)
0.92
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 50%
89%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size diff_size
0.359
Mass File Touch mass_file_touch
0.080
Real PR Conversation Timeline
38 items
llvmorg-github-actions[bot] llvmorg-github-actions[bot] commented on Sep 27, 2026 19:12 UTC
Bot

<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-transforms
@llvm/pr-subscribers-llvm-ir
@llvm/pr-subscribers-llvm-analysis

@llvm/pr-subscribers-compiler-rt-sanitizer

Author: Serge Pavlov (spavloff)

<details>
<summary>Changes</summary>

Floating-point operations in a strictfp function have side effects, which are modeled using memory effects in the form of a read-write access to "inaccessible memory". This helps maintain strictfp semantics but may hinder optimizations. Floating-point operations may depend on rounding mode or not - this fact may be used to reorder them in a more optimal way. Similarly, functions that control floating-point environment (like set_rounding, set_fpmode etc.) also have more specific access than generic read-write. Also, "inaccessible memory" is used in cases other than FP operation, this results in unnecessary restrictions.

This change implements two new memory location to use instead of the access to "inaccessible memory". The "fpcontrol" location is used to represent access to floating-point control modes, of which only rounding mode is currently supported. The other location, "fpstatus", represents access to floating-point exceptions. Together they replace the use of "inaccessible memory".

The new memory locations are not supported in all cases. The Attributor does not support them now, as these locations do not exactly represent memory. Writing to a floating-point control register inside a function does not mean that the function itself changes some floating-point control mode. Supporting these locations in the Attributor requires additional considerations and, probably, new attributes.

The meaning of MemoryEffects::onlyAccessesInaccessibleMem is changed in this commit. Now this method checks not only the "inaccessible memory" but also floating-point environment. This change agrees with the current usage of the method in the compiler sources and will hopefully reduce the risk on misuse.

This change only introduces the new memory locations. Their use in the functions that access the floating-point environment will be implemented in another commit.

This MR was obtained from
https://github.com/llvm/llvm-project/pull/221754 by keeping only the changes required to introduce the new memory locations only.

---
Full diff: https://github.com/llvm/llvm-project/pull/226826.diff

17 Files Affected:

  • (modified) llvm/include/llvm/AsmParser/LLToken.h (+2)

  • (modified) llvm/include/llvm/Support/ModRef.h (+69-7)

  • (modified) llvm/include/llvm/Transforms/IPO/Attributor.h (+2-2)

  • (modified) llvm/lib/Analysis/AliasAnalysis.cpp (+2)

  • (modified) llvm/lib/Analysis/BasicAliasAnalysis.cpp (+5-2)

  • (modified) llvm/lib/Analysis/GlobalsModRef.cpp (+1-1)

  • (modified) llvm/lib/AsmParser/LLLexer.cpp (+2)

  • (modified) llvm/lib/AsmParser/LLParser.cpp (+7-2)

  • (modified) llvm/lib/IR/Attributes.cpp (+31-9)

  • (modified) llvm/lib/Support/ModRef.cpp (+6)

  • (modified) llvm/lib/Transforms/IPO/Attributor.cpp (+3-1)

  • (modified) llvm/lib/Transforms/IPO/AttributorAttributes.cpp (+4-4)

  • (modified) llvm/lib/Transforms/IPO/FunctionAttrs.cpp (+1-1)

  • (modified) llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp (+2)

  • (modified) llvm/test/Assembler/memory-attribute-errors.ll (+3-3)

  • (modified) llvm/test/Assembler/memory-attribute.ll (+30)

  • (modified) llvm/unittests/Support/ModRefTest.cpp (+2-1)
  • ``````

    The server is unavailable at this time. Please wait a few minutes before you try again.
    
    ``````

    </details>

    github-actions[bot] github-actions[bot] commented on Sep 27, 2026 19:15 UTC
    Bot

    <!--LLVM CODE FORMAT COMMENT: {clang-format}-->

    :warning: C/C++ code formatter, clang-format found issues in your code. :warning:

    <details>
    <summary>
    You can test this locally with the following command:
    </summary>

    ``````

    git-clang-format --diff origin/main HEAD --extensions cpp,h -- llvm/include/llvm/AsmParser/LLToken.h llvm/include/llvm/Support/ModRef.h llvm/include/llvm/Transforms/IPO/Attributor.h llvm/lib/Analysis/AliasAnalysis.cpp llvm/lib/Analysis/BasicAliasAnalysis.cpp llvm/lib/Analysis/GlobalsModRef.cpp llvm/lib/AsmParser/LLLexer.cpp llvm/lib/AsmParser/LLParser.cpp llvm/lib/IR/Attributes.cpp llvm/lib/Support/ModRef.cpp llvm/lib/Transforms/IPO/Attributor.cpp llvm/lib/Transforms/IPO/AttributorAttributes.cpp llvm/lib/Transforms/IPO/FunctionAttrs.cpp llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp llvm/unittests/Support/ModRefTest.cpp --diff_from_common_commit
    
    ``
    
    :warning:
    The reproduction instructions above might return results for more than one PR
    in a stack if you are using a stacked PR workflow. You can limit the results by
    changing `origin/main` to the base branch/commit you want to compare against.
    :warning:
    
    </details>
    
    <details>
    <summary>
    View the diff from clang-format here.
    </summary>
    
    
    ``
    diff --git a/llvm/unittests/Support/ModRefTest.cpp b/llvm/unittests/Support/ModRefTest.cpp
    index bbb104872..d74dad12f 100644
    --- a/llvm/unittests/Support/ModRefTest.cpp
    +++ b/llvm/unittests/Support/ModRefTest.cpp
    @@ -19,10 +19,10 @@ namespace {
     TEST(ModRefTest, PrintMemoryEffects) {
       std::string S;
       raw_string_ostream OS(S);
    -  OS << MemoryEffects::none();
    -  EXPECT_EQ(S, "ArgMem: NoModRef, InaccessibleMem: NoModRef, ErrnoMem: "
    -               "NoModRef, Other: NoModRef, TargetMem0: NoModRef, "
    -               "TargetMem1: NoModRef, FPControl: NoModRef, FPStatus: NoModRef");
    +  OS << MemoryEffects::none();
    +  EXPECT_EQ(S, "ArgMem: NoModRef, InaccessibleMem: NoModRef, ErrnoMem: "
    +               "NoModRef, Other: NoModRef, TargetMem0: NoModRef, "
    +               "TargetMem1: NoModRef, FPControl: NoModRef, FPStatus: NoModRef");
     }
     
     } // namespace
    
    
    ``````

    </details>

    CarolineConcatto CarolineConcatto commented on code on Oct 01, 2026 10:26 UTC
    Code Review
    llvm/include/llvm/Transforms/IPO/Attributor.h:1
    @@ -3554,7 +3554,7 @@ struct AANoSync
         SmallVector<Attribute, 2> Attrs;
         A.getAttrs(IRP, {Attribute::Memory}, Attrs, IgnoreSubsumingPositions);
     
    -    MemoryEffects ME = MemoryEffects::unknown();
    +    MemoryEffects ME = MemoryEffects::unknown_mem();

    I dont understand why we only set part of the location here.
    AFAIU this is only initializing ME and then going through all the memory attributes and setting it.

    CarolineConcatto CarolineConcatto commented on code on Oct 01, 2026 10:28 UTC
    Code Review
    llvm/lib/Analysis/AliasAnalysis.cpp:1
    @@ -263,6 +263,8 @@ getModRefInfoInaccessibleAndTargetMemLoc(const MemoryEffects CallUse,
       };
     
       addModRefInfoForLoc(IRMemLocation::InaccessibleMem);
    +  for (auto Loc : MemoryEffects::fpenvLocations())

    The name of the function is
    getModRefInfoInaccessibleAndTargetMemLoc and we are also now checking fp modes.
    There is nothing wrong, but are we saying that fp locations is the same as inaccessible memory?

    CarolineConcatto CarolineConcatto commented on code on Oct 01, 2026 10:53 UTC
    Code Review
    llvm/lib/AsmParser/LLParser.cpp:1
    @@ -2835,7 +2839,8 @@ std::optional<MemoryEffects> LLParser::parseMemoryAttr() {
         std::optional<ModRefInfo> MR = keywordToModRef(Lex.getKind());
         if (!MR) {
           if (Locs.empty())
    -        tokError("expected memory location (argmem, inaccessiblemem, errnomem) "
    +        tokError("expected memory location (argmem, inaccessiblemem, errnomem, "
    +                 "fpcontrol, fpstatus) "

    Why are you adding this here:
    fpcontrol, fpstatus
    I think we can remove, mainly because in line 2868 you are not setting fp memory locations

    CarolineConcatto CarolineConcatto commented on code on Oct 01, 2026 10:59 UTC
    Code Review
    llvm/lib/AsmParser/LLParser.cpp:1
    @@ -2860,7 +2865,7 @@ std::optional<MemoryEffects> LLParser::parseMemoryAttr() {
             tokError("default access kind must be specified first");
             return std::nullopt;
           }
    -      ME = MemoryEffects(*MR);
    +      ME = MemoryEffects(*MR, /*NoFPEnvMarker*/ false);

    This set Inaccessible memory, but does not set fp memory locations.
    It is a bit strange that sometime FP memory location is equal to inaccessible memory(onlyAccessesInaccessibleMem or in getModRefInfoInaccessibleAndTargetMemLoc ) and sometimes is not.
    Like now, FP locations is not being treated as inaccessible memory, because this sets all locations including inaccessible memory.
    Maybe it would be better to differentiate them, like we did for target_memory.

    CarolineConcatto CarolineConcatto commented on code on Oct 01, 2026 11:07 UTC
    Code Review
    llvm/lib/Transforms/IPO/FunctionAttrs.cpp:1
    @@ -285,7 +285,7 @@ static void addMemoryAttrs(const SCCNodeSet &SCCNodes, AARGetterT &&AARGetter,
         ME |= FnME;
         RecursiveArgME |= FnRecursiveArgME;
         // Reached bottom of the lattice, we will not be able to improve the result.
    -    if (ME == MemoryEffects::unknown())
    +    if (ME == MemoryEffects::unknown_mem())

    For all the Transform changes if you keep this checking MemoryEffects::unknown() and the memory set(ME = MemoryEffects(ME.getModRef());) you still set all locations, what would be a problem?
    I dont understand what is the problem of setting all bits for now and checking all bits for the memory location.

    CarolineConcatto CarolineConcatto commented on code on Oct 01, 2026 11:08 UTC
    Code Review
    llvm/test/Assembler/memory-attribute.ll:1
    @@ -148,3 +148,33 @@ declare void @fn_write_target_mem_read_write()
     ; CHECK: @fn_all_readwrite
     declare void @fn_all_readwrite()
         memory(readwrite, target_mem: read)
    +
    +; CHECK: Function Attrs: memory(fpcontrol: read)
    +; CHECK: @fn_read_fpcontrol
    +declare void @fn_read_fpcontrol()

    Can you combine this with target memory as well, so we can check the changes you did in the parser .

    spavloff spavloff commented on Oct 12, 2026 09:13 UTC
    Author

    The new variant of this PR treats the floating-point locations same as other location. It is more consistent with the current design of memory effects, than a special treatment of the FP locations. It however requires changes in tests, where additional fpenv: none may be required. To reduce number of such tests, the changes not necessary to support the new locations are removed.

    spavloff spavloff commented on code on Oct 12, 2026 09:54 UTC
    Code Review
    llvm/include/llvm/Transforms/IPO/Attributor.h:1
    @@ -3554,7 +3554,7 @@ struct AANoSync
         SmallVector<Attribute, 2> Attrs;
         A.getAttrs(IRP, {Attribute::Memory}, Attrs, IgnoreSubsumingPositions);
     
    -    MemoryEffects ME = MemoryEffects::unknown();
    +    MemoryEffects ME = MemoryEffects::unknown_mem();

    You are right. Now unknown_mem is removed.

    spavloff spavloff commented on code on Oct 12, 2026 09:54 UTC
    Code Review
    llvm/lib/Analysis/AliasAnalysis.cpp:1
    @@ -263,6 +263,8 @@ getModRefInfoInaccessibleAndTargetMemLoc(const MemoryEffects CallUse,
       };
     
       addModRefInfoForLoc(IRMemLocation::InaccessibleMem);
    +  for (auto Loc : MemoryEffects::fpenvLocations())

    The function is now renamed to getModRefInfoNonaddressableMemLoc.

    spavloff spavloff commented on code on Oct 12, 2026 09:54 UTC
    Code Review
    llvm/lib/AsmParser/LLParser.cpp:1
    @@ -2835,7 +2839,8 @@ std::optional<MemoryEffects> LLParser::parseMemoryAttr() {
         std::optional<ModRefInfo> MR = keywordToModRef(Lex.getKind());
         if (!MR) {
           if (Locs.empty())
    -        tokError("expected memory location (argmem, inaccessiblemem, errnomem) "
    +        tokError("expected memory location (argmem, inaccessiblemem, errnomem, "
    +                 "fpcontrol, fpstatus) "

    User may use this attributes in their asm files.

    spavloff spavloff commented on code on Oct 12, 2026 09:55 UTC
    Code Review
    llvm/lib/AsmParser/LLParser.cpp:1
    @@ -2860,7 +2865,7 @@ std::optional<MemoryEffects> LLParser::parseMemoryAttr() {
             tokError("default access kind must be specified first");
             return std::nullopt;
           }
    -      ME = MemoryEffects(*MR);
    +      ME = MemoryEffects(*MR, /*NoFPEnvMarker*/ false);

    Now FP locations behave exactly as other memories. Originally it seemed that treating these locations specifically, (like using natural default settings) can provide more convenient design. However it is hard to combine defferent logic in a single solution. Treating all memory locations uniformly seems more clear implementation.

    spavloff spavloff commented on code on Oct 12, 2026 09:55 UTC
    Code Review
    llvm/lib/Transforms/IPO/FunctionAttrs.cpp:1
    @@ -285,7 +285,7 @@ static void addMemoryAttrs(const SCCNodeSet &SCCNodes, AARGetterT &&AARGetter,
         ME |= FnME;
         RecursiveArgME |= FnRecursiveArgME;
         // Reached bottom of the lattice, we will not be able to improve the result.
    -    if (ME == MemoryEffects::unknown())
    +    if (ME == MemoryEffects::unknown_mem())

    Now unknown_mem is removed.

    FP access has more complicated restrictions. For example read access to FP status bits require setting strictfp attribute. The initial intent was to uses NoModRef for FP locations as this is the common case. Now it requires more careful treatment in attribute deduction.

    spavloff spavloff commented on code on Oct 12, 2026 09:55 UTC
    Code Review
    llvm/test/Assembler/memory-attribute.ll:1
    @@ -148,3 +148,33 @@ declare void @fn_write_target_mem_read_write()
     ; CHECK: @fn_all_readwrite
     declare void @fn_all_readwrite()
         memory(readwrite, target_mem: read)
    +
    +; CHECK: Function Attrs: memory(fpcontrol: read)
    +; CHECK: @fn_read_fpcontrol
    +declare void @fn_read_fpcontrol()

    The new test cases were added.

    spavloff spavloff commented on Oct 28, 2026 15:51 UTC
    Author

    Does the new version resolve the comments?

    spavloff spavloff commented on Nov 03, 2026 17:57 UTC
    Author

    Ping.

    krzysz00 krzysz00 commented on code on Nov 03, 2026 18:52 UTC
    Code Review
    llvm/include/llvm/Support/ModRef.h:1
    @@ -69,10 +69,15 @@ enum class IRMemLocation {
       /// Represents target specific state.
       TargetMem0 = 4,
       TargetMem1 = 5,
    +  /// Floating-point control modes.
    +  FPControl = 6,
    +  /// Floating-point status bits.
    +  FPStatus = 7,
     
       /// Helpers to iterate all locations in the MemoryEffectsBase class.
       First = ArgMem,
    -  Last = TargetMem1,
    +  LastMem = TargetMem1,

    Don't think we need this?

    krzysz00 krzysz00 commented on code on Nov 03, 2026 18:53 UTC
    Code Review
    llvm/include/llvm/Support/ModRef.h:1
    @@ -295,6 +333,22 @@ template <typename LocationEnum> class MemoryEffectsBase {
         return true;
       }
     
    +  /// Whether location represents floating-point environment.
    +  static bool isFPEnvMemLoc(IRMemLocation Loc) {
    +    for (auto L : fpenvLocations())
    +      if (Loc == L)
    +        return true;
    +    return false;
    +  }
    +
    +  /// Whether all floating-point locations are not accessed.
    +  bool doesNotAccessFPEnv() const {
    +    for (auto L : fpenvLocations())
    +      if (getModRef(L) != ModRefInfo::NoModRef)

    Should this be an llvm::any_of - and similarly above?

    krzysz00 krzysz00 commented on code on Nov 03, 2026 18:56 UTC
    Code Review
    llvm/lib/IR/Attributes.cpp:1
    @@ -644,26 +644,43 @@ std::string Attribute::getAsString(bool InAttrGrp) const {
           OS << getModRefStr(OtherMR);
         }
     
    -    bool TargetPrintedForAll = false;
    +    bool SkipLocGroup = false;
    +    IRMemLocation LastToSkip;
    +    const auto isFPEnvMemLocSameForAll = [](MemoryEffects ME) -> bool {
    +      return ME.getModRef(IRMemLocation::FPControl) ==
    +             ME.getModRef(IRMemLocation::FPStatus);
    +    };
         for (auto Loc : MemoryEffects::locations()) {
           ModRefInfo MR = ME.getModRef(Loc);
           if (MR == OtherMR)
             continue;
     
    -      if (!First && !TargetPrintedForAll)
    +      if (SkipLocGroup) {
    +        if (Loc == LastToSkip)
    +          SkipLocGroup = false;
    +        continue;
    +      }
    +
    +      if (!First && !SkipLocGroup)
             OS << ", ";
           First = false;
     
    +      if (MemoryEffects::isFPEnvMemLoc(Loc) && isFPEnvMemLocSameForAll(ME)) {
    +        OS << "fpenv: ";

    To make sure I'm reading this right, this is a parser convenience for when the control and status words have the same effects?

    krzysz00 krzysz00 commented on code on Nov 03, 2026 18:58 UTC
    Code Review
    llvm/unittests/IR/AttributesTest.cpp:1
    @@ -818,4 +818,82 @@ TEST(Attributes, ListIntersect) {
       ASSERT_TRUE(Res->hasParamAttr(3, Attribute::ByVal));
     }
     
    +TEST(Attributes, AsString) {

    Do we need this? It seems redundant with the lit tests.

    krzysz00 krzysz00 commented on code on Nov 03, 2026 18:58 UTC
    Code Review
    llvm/unittests/Analysis/AliasAnalysisTest.cpp:1
    @@ -221,6 +222,88 @@ TEST_F(AliasAnalysisTest, getModRefInfo) {
       EXPECT_EQ(AA.getModRefInfo(Foo, Foo), ModRefInfo::ModRef);
     }
     
    +TEST_F(AliasAnalysisTest, getFPModRefInfo) {

    This might be better expressed as a lit test?

    krzysz00 krzysz00 commented on Nov 03, 2026 18:59 UTC
    Reviewer

    I think this change is pretty reasonable, I've just got a few minor notes, and am willing to stamp after they're addressed

    nikic nikic commented on code on Nov 04, 2026 15:10 UTC
    Code Review
    llvm/include/llvm/Support/ModRef.h:1
    @@ -107,6 +111,11 @@ template <typename LocationEnum> class MemoryEffectsBase {
         return enum_seq_inclusive(Location::TargetMem0, Location::TargetMem1,
                                   force_iteration_on_noniterable_enum);
       }
    +  /// Returns iterator over floating-point state locations.
    +  static auto fpenvLocations() {

      static auto fpEnvLocations() {
    

    And similar for the other ones. I think this is more consistent with capitalization of other members in this class.

    nikic nikic commented on code on Nov 04, 2026 15:11 UTC
    Code Review
    llvm/include/llvm/Support/ModRef.h:1
    @@ -160,6 +169,32 @@ template <typename LocationEnum> class MemoryEffectsBase {
         return MemoryEffectsBase(Location::Other, MR);
       }
     
    +  /// Create MemoryEffectsBase that can only access floating-point state
    +  /// register.

      /// registers.
    

    (or add "the")

    nikic nikic commented on code on Nov 04, 2026 15:13 UTC
    Code Review
    llvm/lib/AsmParser/LLParser.cpp:1
    @@ -2835,7 +2846,8 @@ std::optional<MemoryEffects> LLParser::parseMemoryAttr() {
         std::optional<ModRefInfo> MR = keywordToModRef(Lex.getKind());
         if (!MR) {
           if (Locs.empty())
    -        tokError("expected memory location (argmem, inaccessiblemem, errnomem) "
    +        tokError("expected memory location (argmem, inaccessiblemem, errnomem, "
    +                 "fpcontrol, fpstatus) "

    Missing fpenv?

    nikic nikic commented on code on Nov 04, 2026 15:15 UTC
    Code Review
    llvm/test/Assembler/memory-attribute.ll:1
    @@ -148,3 +148,53 @@ declare void @fn_write_target_mem_read_write()
     ; CHECK: @fn_all_readwrite
     declare void @fn_all_readwrite()
         memory(readwrite, target_mem: read)
    +
    +; CHECK: Function Attrs: memory(fpcontrol: read)
    +; CHECK: @fn_read_fpcontrol
    +declare void @fn_read_fpcontrol()
    +    memory(fpcontrol: read)
    +
    +; CHECK: Function Attrs: memory(fpcontrol: write)
    +; CHECK: @fn_write_fpcontrol
    +declare void @fn_write_fpcontrol()
    +    memory(fpcontrol: write)
    +
    +; CHECK: Function Attrs: memory(fpstatus: read)
    +; CHECK: @fn_read_fpstatus
    +declare void @fn_read_fpstatus()
    +    memory(fpstatus: read)
    +
    +; CHECK: Function Attrs: memory(fpstatus: readwrite)
    +; CHECK: @fn_readwrite_fpstatus
    +declare void @fn_readwrite_fpstatus()
    +    memory(fpstatus: readwrite)
    +
    +; CHECK: Function Attrs: memory(fpenv: readwrite)
    +; CHECK: @fn_readwrite_fpenv
    +declare void @fn_readwrite_fpenv()
    +    memory(fpenv: readwrite)
    +
    +; CHECK: Function Attrs: memory(fpcontrol: read, fpstatus: readwrite)
    +; CHECK: @fn_read_fpcontrol_readwrite_fpstatus
    +declare void @fn_read_fpcontrol_readwrite_fpstatus()
    +    memory(fpcontrol: read, fpstatus: readwrite)
    +
    +; CHECK: Function Attrs: memory(write, fpcontrol: read)
    +; CHECK: @fn_read_fpcontrol_write_mem
    +declare void @fn_read_fpcontrol_write_mem()
    +    memory(write, fpcontrol: read)
    +
    +; CHECK: Function Attrs: memory(write, target_mem: readwrite, fpcontrol: read)
    +; CHECK: @fn_read_fpcontrol_rw_target_write_mem
    +declare void @fn_read_fpcontrol_rw_target_write_mem()
    +    memory(write, target_mem: readwrite, fpcontrol: read)
    +
    +; CHECK: Function Attrs: memory(write, target_mem0: read, fpenv: read)
    +; CHECK: @fn_read_fpenv_read_target0_write_mem
    +declare void @fn_read_fpenv_read_target0_write_mem()
    +    memory(write, target_mem0: read, fpenv: read)
    +
    +; CHECK: Function Attrs: memory(write, target_mem: readwrite, fpenv: read)
    +; CHECK: @fn_read_fpenv_rw_target_write_mem
    +declare void @fn_read_fpenv_rw_target_write_mem()
    +    memory(write, target_mem: readwrite, fpenv: read)

    Missing a test with both fpenv and fpcontrol/fpstatus, I think?

    nikic nikic commented on code on Nov 04, 2026 15:16 UTC
    Code Review
    llvm/unittests/Analysis/AliasAnalysisTest.cpp:1
    @@ -221,6 +222,88 @@ TEST_F(AliasAnalysisTest, getModRefInfo) {
       EXPECT_EQ(AA.getModRefInfo(Foo, Foo), ModRefInfo::ModRef);
     }
     
    +TEST_F(AliasAnalysisTest, getFPModRefInfo) {

    Yes, please.

    nikic nikic commented on Nov 04, 2026 15:19 UTC
    Contributor

    This generally looks reasonable to me. Something I'm unhappy about is the inaccessiblemem vs nonaddressablemem -- those words mean the same thing.

    I think the way I'd model this is to have inaccessiblemem refer to all kinds of inaccessible memory and replace the old inaccessiblemem by other_inaccessiblemem, as the category for inaccessible memory that has not been otherwise categorized. I expect we have a bunch of inaccessiblemem queries in the code base that really ought to be covering the new fpenv memory as well.

    spavloff spavloff commented on code on Nov 09, 2026 17:04 UTC
    Code Review
    llvm/include/llvm/Support/ModRef.h:1
    @@ -69,10 +69,15 @@ enum class IRMemLocation {
       /// Represents target specific state.
       TargetMem0 = 4,
       TargetMem1 = 5,
    +  /// Floating-point control modes.
    +  FPControl = 6,
    +  /// Floating-point status bits.
    +  FPStatus = 7,
     
       /// Helpers to iterate all locations in the MemoryEffectsBase class.
       First = ArgMem,
    -  Last = TargetMem1,
    +  LastMem = TargetMem1,

    Removed.

    spavloff spavloff commented on code on Nov 09, 2026 17:05 UTC
    Code Review
    llvm/lib/IR/Attributes.cpp:1
    @@ -644,26 +644,43 @@ std::string Attribute::getAsString(bool InAttrGrp) const {
           OS << getModRefStr(OtherMR);
         }
     
    -    bool TargetPrintedForAll = false;
    +    bool SkipLocGroup = false;
    +    IRMemLocation LastToSkip;
    +    const auto isFPEnvMemLocSameForAll = [](MemoryEffects ME) -> bool {
    +      return ME.getModRef(IRMemLocation::FPControl) ==
    +             ME.getModRef(IRMemLocation::FPStatus);
    +    };
         for (auto Loc : MemoryEffects::locations()) {
           ModRefInfo MR = ME.getModRef(Loc);
           if (MR == OtherMR)
             continue;
     
    -      if (!First && !TargetPrintedForAll)
    +      if (SkipLocGroup) {
    +        if (Loc == LastToSkip)
    +          SkipLocGroup = false;
    +        continue;
    +      }
    +
    +      if (!First && !SkipLocGroup)
             OS << ", ";
           First = false;
     
    +      if (MemoryEffects::isFPEnvMemLoc(Loc) && isFPEnvMemLocSameForAll(ME)) {
    +        OS << "fpenv: ";

    Exactly. This is made similar to the TargetMem.

    spavloff spavloff commented on code on Nov 09, 2026 17:07 UTC
    Code Review
    llvm/unittests/Analysis/AliasAnalysisTest.cpp:1
    @@ -221,6 +222,88 @@ TEST_F(AliasAnalysisTest, getModRefInfo) {
       EXPECT_EQ(AA.getModRefInfo(Foo, Foo), ModRefInfo::ModRef);
     }
     
    +TEST_F(AliasAnalysisTest, getFPModRefInfo) {

    The lit test is in llvm/test/Analysis/BasicAA/fpenv.ll

    spavloff spavloff commented on code on Nov 09, 2026 17:08 UTC
    Code Review
    llvm/include/llvm/Support/ModRef.h:1
    @@ -107,6 +111,11 @@ template <typename LocationEnum> class MemoryEffectsBase {
         return enum_seq_inclusive(Location::TargetMem0, Location::TargetMem1,
                                   force_iteration_on_noniterable_enum);
       }
    +  /// Returns iterator over floating-point state locations.
    +  static auto fpenvLocations() {

    Also updated fpEnvOnly, fpControlOnly and fpStatusOnly.

    spavloff spavloff commented on code on Nov 09, 2026 17:09 UTC
    Code Review
    llvm/include/llvm/Support/ModRef.h:1
    @@ -160,6 +169,32 @@ template <typename LocationEnum> class MemoryEffectsBase {
         return MemoryEffectsBase(Location::Other, MR);
       }
     
    +  /// Create MemoryEffectsBase that can only access floating-point state
    +  /// register.

    Fixed (used registers).

    spavloff spavloff commented on code on Nov 09, 2026 17:10 UTC
    Code Review
    llvm/test/Assembler/memory-attribute.ll:1
    @@ -148,3 +148,53 @@ declare void @fn_write_target_mem_read_write()
     ; CHECK: @fn_all_readwrite
     declare void @fn_all_readwrite()
         memory(readwrite, target_mem: read)
    +
    +; CHECK: Function Attrs: memory(fpcontrol: read)
    +; CHECK: @fn_read_fpcontrol
    +declare void @fn_read_fpcontrol()
    +    memory(fpcontrol: read)
    +
    +; CHECK: Function Attrs: memory(fpcontrol: write)
    +; CHECK: @fn_write_fpcontrol
    +declare void @fn_write_fpcontrol()
    +    memory(fpcontrol: write)
    +
    +; CHECK: Function Attrs: memory(fpstatus: read)
    +; CHECK: @fn_read_fpstatus
    +declare void @fn_read_fpstatus()
    +    memory(fpstatus: read)
    +
    +; CHECK: Function Attrs: memory(fpstatus: readwrite)
    +; CHECK: @fn_readwrite_fpstatus
    +declare void @fn_readwrite_fpstatus()
    +    memory(fpstatus: readwrite)
    +
    +; CHECK: Function Attrs: memory(fpenv: readwrite)
    +; CHECK: @fn_readwrite_fpenv
    +declare void @fn_readwrite_fpenv()
    +    memory(fpenv: readwrite)
    +
    +; CHECK: Function Attrs: memory(fpcontrol: read, fpstatus: readwrite)
    +; CHECK: @fn_read_fpcontrol_readwrite_fpstatus
    +declare void @fn_read_fpcontrol_readwrite_fpstatus()
    +    memory(fpcontrol: read, fpstatus: readwrite)
    +
    +; CHECK: Function Attrs: memory(write, fpcontrol: read)
    +; CHECK: @fn_read_fpcontrol_write_mem
    +declare void @fn_read_fpcontrol_write_mem()
    +    memory(write, fpcontrol: read)
    +
    +; CHECK: Function Attrs: memory(write, target_mem: readwrite, fpcontrol: read)
    +; CHECK: @fn_read_fpcontrol_rw_target_write_mem
    +declare void @fn_read_fpcontrol_rw_target_write_mem()
    +    memory(write, target_mem: readwrite, fpcontrol: read)
    +
    +; CHECK: Function Attrs: memory(write, target_mem0: read, fpenv: read)
    +; CHECK: @fn_read_fpenv_read_target0_write_mem
    +declare void @fn_read_fpenv_read_target0_write_mem()
    +    memory(write, target_mem0: read, fpenv: read)
    +
    +; CHECK: Function Attrs: memory(write, target_mem: readwrite, fpenv: read)
    +; CHECK: @fn_read_fpenv_rw_target_write_mem
    +declare void @fn_read_fpenv_rw_target_write_mem()
    +    memory(write, target_mem: readwrite, fpenv: read)

    Such test is in llvm/test/Assembler/memory-attribute-errors.ll.

    spavloff spavloff commented on Nov 09, 2026 17:11 UTC
    Author

    To address the naming problem, either IRMemLocation::InaccessibleMem should be renamed, or functions like onlyAccessesNonaddressableMem() should be given a different stem.

    If IRMemLocation::InaccessibleMem is renamed, many of the existing calls to functions like onlyAccessesInaccessibleMemory will be preserved, but not all. This is an advantage - it requires fewer changes in the code. However, tests in this case also should be updated. There are about 900 occurences of inaccessiblemem in tests, which make this approach invasive. Additionally, It is not easy to invent a descriptive name for inaccessiblemem, as it is used as a generic way to implement memory-like ordering.

    If the stem inaccessible is changed to something new, most of the functions like onlyAccessesInaccessibleMemory will have to be changed. However, the number of such calls is not large, and they must be reviewed for update anyway, no matter which approach is chosen.

    In this revision, a low-invasive solution is proposed. IRMemLocation::InaccessibleMem remains intact, and only function names are changed. The memory locations InaccessibleMem, TargetMem*, FPControl and FPStatus are groupped into "PseudoMem". None of them are true memory location, and none allow pointers. In this patch only a minimal set of calls are updated to keep the patch compact. A full update of the functions will be implemented in follow-up patches.

    spavloff spavloff commented on Nov 23, 2026 18:15 UTC
    Author

    I think the way I'd model this is to have inaccessiblemem refer to all kinds of inaccessible memory and replace the old inaccessiblemem by other_inaccessiblemem, as the category for inaccessible memory that has not been otherwise categorized. I expect we have a bunch of inaccessiblemem queries in the code base that really ought to be covering the new fpenv memory as well.

    The first part of such solution is presented in https://github.com/llvm/llvm-project/pull/245318. It renames the existing inaccessiblemem.

    Assignees
    spavloff spavloff
    Labels
    risk: low confidence: 89.7% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 74.4% (HIGH) · Higher = larger blast radius
    74.4%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 89.7% · Lower = rushed or shallow review
    89.7%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 7.6% · Safe to merge
    7.6%