[all-commits] [llvm/llvm-project] 5afbfe: [ConstantFold] Make icmp of gep fold offset based

Nikita Popov via All-commits all-commits at lists.llvm.org
Mon Jan 3 00:45:22 PST 2022


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 5afbfe33e7d6ce40af0ad6d99421b443c45b351b
      https://github.com/llvm/llvm-project/commit/5afbfe33e7d6ce40af0ad6d99421b443c45b351b
  Author: Nikita Popov <npopov at redhat.com>
  Date:   2022-01-03 (Mon, 03 Jan 2022)

  Changed paths:
    M llvm/lib/Analysis/ConstantFolding.cpp
    M llvm/lib/IR/ConstantFold.cpp
    M llvm/test/Assembler/ConstantExprFold.ll
    M llvm/test/Transforms/InstSimplify/ConstProp/icmp-global.ll

  Log Message:
  -----------
  [ConstantFold] Make icmp of gep fold offset based

We can fold an equality or unsigned icmp between base+offset1 and
base+offset2 with inbounds offsets by comparing the offsets directly.

This replaces a pair of specialized folds that tried to reason
based on the GEP structure instead. One of those folds was plain
wrong (because it does not account for negative offsets), while
the other is unnecessarily complicated and limited (e.g. it will
fail with bitcasts involved).

The disadvantage of this change is that it requires data layout,
so the fold is no longer performed by datalayout-independent
constant folding. I don't think this is a loss in practice, but
it does regress the ConstantExprFold.ll test, which checks folding
without running any passes.

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




More information about the All-commits mailing list