[all-commits] [llvm/llvm-project] b7cd29: [GlobalOpt] Treat null-check of loaded value as us...

Vedant Kumar via All-commits all-commits at lists.llvm.org
Mon Mar 23 22:36:16 PDT 2020


  Branch: refs/heads/master
  Home:   https://github.com/llvm/llvm-project
  Commit: b7cd291c1542aee12c9e9fde6c411314a163a8ea
      https://github.com/llvm/llvm-project/commit/b7cd291c1542aee12c9e9fde6c411314a163a8ea
  Author: Vedant Kumar <vsk at apple.com>
  Date:   2020-03-23 (Mon, 23 Mar 2020)

  Changed paths:
    M llvm/lib/Transforms/IPO/GlobalOpt.cpp
    A llvm/test/Transforms/GlobalOpt/null-check-is-use-pr35760.ll

  Log Message:
  -----------
  [GlobalOpt] Treat null-check of loaded value as use of global (PR35760)

PR35760 shows an example program which, when compiled with `clang -O0`
or gcc at any optimization level, prints '0'. However, llvm transforms
the program in a way that causes it to print '1'.

Fix the issue by having `AllUsesOfValueWillTrapIfNull` return false when
analyzing a load from a global which is used by an `icmp`. This special
case was untested [0] so this is just deleting dead code.

An alternative fix might be to change the GlobalStatus analysis for the
global to report "Stored" instead of "StoredOnce". However, "StoredOnce"
is appropriate when only one value other than the initializer is stored
to the global.

[0]
http://lab.llvm.org:8080/coverage/coverage-reports/coverage/Users/buildslave/jenkins/workspace/coverage/llvm-project/llvm/lib/Transforms/IPO/GlobalOpt.cpp.html#L662

Differential Revision: https://reviews.llvm.org/D76645




More information about the All-commits mailing list