Skip to content

Duplicate/redundant nimZeroMem() in --mm:refc #23383

Description

@tersec

Description

import std/strformat
discard parseStandardFormatSpecifier("")

is one example, but browsing generated C with --mm:refc shows many of them.

C compilers aren't necessarily reliable, nor should they be, at detecting that this is a verifiably idempotent operation, so the later calls can be removed, so it creates real runtime (profiled, even) overhead.

Example of generated duplicate nimZeroMem for that code in @mNim@slib@spure@sstrformat.nim.c:

static N_INLINE(tyObject_HSlice__1F9c6PBLtnXQNAmUXyCBSBw,
                dotdot___stdZenumutils_90)(NI a, NI b) {
  tyObject_HSlice__1F9c6PBLtnXQNAmUXyCBSBw result;
  nimZeroMem((void *)(&result),
             sizeof(tyObject_HSlice__1F9c6PBLtnXQNAmUXyCBSBw));
  nimZeroMem((void *)(&result),
             sizeof(tyObject_HSlice__1F9c6PBLtnXQNAmUXyCBSBw));
  result.a = a;
  result.b = b;
  popFrame();
  return result;
}

In this case, an tyObject_HSlice__1F9c6PBLtnXQNAmUXyCBSBw isn't huge, but for larger objects and/or in loops, this becomes more significant.

Nim Version

Nim Compiler Version 1.6.18 [Linux: amd64]
Compiled at 2024-03-09
Copyright (c) 2006-2023 by Andreas Rumpf

git hash: a749a8b742bd0a4272c26a65517275db4720e58a
active boot switches: -d:release
Nim Compiler Version 2.0.3 [Linux: amd64]
Compiled at 2024-03-09
Copyright (c) 2006-2023 by Andreas Rumpf

git hash: e374759f29da733f3c404718c333f5f3cb5f332d
active boot switches: -d:release
Nim Compiler Version 2.1.1 [Linux: amd64]
Compiled at 2024-03-09
Copyright (c) 2006-2024 by Andreas Rumpf

git hash: 94c599687796f4ee3872c8aa866827b9ed33f52b
active boot switches: -d:release

Current Output

static N_INLINE(tyObject_HSlice__1F9c6PBLtnXQNAmUXyCBSBw,
                dotdot___stdZenumutils_90)(NI a, NI b) {
  tyObject_HSlice__1F9c6PBLtnXQNAmUXyCBSBw result;
  nimZeroMem((void *)(&result),
             sizeof(tyObject_HSlice__1F9c6PBLtnXQNAmUXyCBSBw));
  nimZeroMem((void *)(&result),
             sizeof(tyObject_HSlice__1F9c6PBLtnXQNAmUXyCBSBw));
  result.a = a;
  result.b = b;
  popFrame();
  return result;
}

Expected Output

No duplicate nimZeroMem() calls

Possible Solution

No response

Additional Information

No response

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions