[GlobalOpt] Fix memset handling in global ctor evaluation (PR55859)
authorNikita Popov <npopov@redhat.com>
Fri, 24 Jun 2022 14:02:28 +0000 (16:02 +0200)
committerNikita Popov <npopov@redhat.com>
Mon, 27 Jun 2022 14:50:49 +0000 (16:50 +0200)
commitf65c88c42fdd0e46d16fe31737e6627c56de77c3
tree5b681678e459ac9b63768a329e8244b888bb6200
parent8fa2e67979e56db3cc511ff1af920b4fa02fb473
[GlobalOpt] Fix memset handling in global ctor evaluation (PR55859)

The global ctor evaluator currently handles by checking whether the
memset memory is already zero, and skips it in that case. However,
it only actually checks the first byte of the memory being set.

This patch extends the code to check all bytes being set. This is
done byte-by-byte to avoid converting undef values to zeros in
larger reads. However, the handling is still not completely correct,
because there might still be padding bytes (though probably this
doesn't matter much in practice, as I'd expect global variable
padding to be zero-initialized in practice).

Mostly fixes https://github.com/llvm/llvm-project/issues/55859.

Differential Revision: https://reviews.llvm.org/D128532
llvm/include/llvm/Transforms/Utils/Evaluator.h
llvm/lib/Transforms/Utils/Evaluator.cpp
llvm/test/Transforms/GlobalOpt/ctor-memset.ll