[InstCombine][DebugInfo] Fold constants wrapped in metadata
authorDavid Stenberg <david.stenberg@ericsson.com>
Thu, 30 Jan 2020 14:33:28 +0000 (15:33 +0100)
committerDavid Stenberg <david.stenberg@ericsson.com>
Thu, 30 Jan 2020 14:50:16 +0000 (15:50 +0100)
commitb54a8ec1bcd3689771c847cb37515b627034e518
tree10875ddeb854598ffe937f9cddfc9a575c44992a
parentd6b83d6ba5a1a07e8d4398b28674e181b59c3455
[InstCombine][DebugInfo] Fold constants wrapped in metadata

Summary:
When constant folding, constants that are wrapped in metadata were not
folded. This could lead to dbg.values being the only user of a constant
expression, due to the non-dbg uses having been rewritten, resulting in
the constant later on being removed by some other pass. This occurred
with the attached test case, in which the non-rewritten GEP in the
dbg.value intrinsic was later on removed by globalopt.

This patch makes the code look through metadata and fold such constants.

I guess that we in the future may want to allow dbg.values using GEPs and
other constant expressions to be emittable even if there are no non-dbg
uses, but for example SelectionDAG does not support that.

Reviewers: jmorse, aprantl, vsk, davide

Reviewed By: aprantl, vsk, davide

Subscribers: hiraditya, llvm-commits

Tags: #debug-info, #llvm

Differential Revision: https://reviews.llvm.org/D73630
llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
llvm/test/Transforms/InstCombine/constant-fold-metadata-wrapped.ll [new file with mode: 0644]