[all-commits] [llvm/llvm-project] 240431: [instsimplify] Fix a miscompile with zero sized al...

Philip Reames via All-commits all-commits at lists.llvm.org
Thu Feb 17 09:27:51 PST 2022


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 2404313d8023d2a650f4cd12f8b4e334c58f5736
      https://github.com/llvm/llvm-project/commit/2404313d8023d2a650f4cd12f8b4e334c58f5736
  Author: Philip Reames <listmail at philipreames.com>
  Date:   2022-02-17 (Thu, 17 Feb 2022)

  Changed paths:
    M llvm/lib/Analysis/InstructionSimplify.cpp
    M llvm/test/Transforms/InstSimplify/compare.ll

  Log Message:
  -----------
  [instsimplify] Fix a miscompile with zero sized allocas

Remove some code which tried to handle the case of comparing two allocas where an object size could not be precisely computed.  This code had zero coverage in tree, and at least one nasty bug.

The bug comes from the fact that the code uses the size of the result pointer as a proxy for whether the alloca can be of size zero.  Since the result of an alloca is *always* a pointer type, and a pointer type can *never* be empty, this check was a nop.  As a result, we blindly consider a zero offset from two allocas to never be equal.  They can in fact be equal when one or more of the allocas is zero sized.

This is particularly ugly because instcombine contains the exact opposite rule.  If instcombine reaches the allocas first, it combines them into one (making them equal).  If instsimplify reaches the compare first, it would consider them not equal.  This creates all kinds of fun scenarios for order of optimization reaching different and contradictory conclusions.




More information about the All-commits mailing list