[all-commits] [llvm/llvm-project] 603ae6: [InstCombine] Precommit tests for D101423 (NFC)

Juneyoung Lee via All-commits all-commits at lists.llvm.org
Sat May 1 19:55:37 PDT 2021


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 603ae6082bcb9e7b8ae9f288c007488f144d9d22
      https://github.com/llvm/llvm-project/commit/603ae6082bcb9e7b8ae9f288c007488f144d9d22
  Author: Juneyoung Lee <aqjune at gmail.com>
  Date:   2021-05-02 (Sun, 02 May 2021)

  Changed paths:
    A llvm/test/Transforms/InstCombine/div-by-0-guard-before-smul_ov-not.ll
    A llvm/test/Transforms/InstCombine/div-by-0-guard-before-smul_ov.ll
    A llvm/test/Transforms/InstCombine/div-by-0-guard-before-umul_ov-not.ll
    A llvm/test/Transforms/InstCombine/div-by-0-guard-before-umul_ov.ll

  Log Message:
  -----------
  [InstCombine] Precommit tests for D101423 (NFC)


  Commit: 1977c53b2ae425541a0ef329ca10cc8d5cacd0cd
      https://github.com/llvm/llvm-project/commit/1977c53b2ae425541a0ef329ca10cc8d5cacd0cd
  Author: Juneyoung Lee <aqjune at gmail.com>
  Date:   2021-05-02 (Sun, 02 May 2021)

  Changed paths:
    A llvm/include/llvm/Analysis/OverflowInstAnalysis.h
    M llvm/lib/Analysis/CMakeLists.txt
    M llvm/lib/Analysis/InstructionSimplify.cpp
    A llvm/lib/Analysis/OverflowInstAnalysis.cpp
    M llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
    M llvm/test/Transforms/InstCombine/div-by-0-guard-before-smul_ov-not.ll
    M llvm/test/Transforms/InstCombine/div-by-0-guard-before-smul_ov.ll
    M llvm/test/Transforms/InstCombine/div-by-0-guard-before-umul_ov-not.ll
    M llvm/test/Transforms/InstCombine/div-by-0-guard-before-umul_ov.ll

  Log Message:
  -----------
  [InstCombine] Fold overflow bit of [u|s]mul.with.overflow in a poison-safe way

As discussed in D101191, this patch adds a poison-safe folding of overflow bit check:
```
  %Op0 = icmp ne i4 %X, 0
  %Agg = call { i4, i1 } @llvm.[us]mul.with.overflow.i4(i4 %X, i4 %Y)
  %Op1 = extractvalue { i4, i1 } %Agg, 1
  %ret = select i1 %Op0, i1 %Op1, i1 false
=>
  %Y.fr = freeze %Y
  %Agg = call { i4, i1 } @llvm.[us]mul.with.overflow.i4(i4 %X, i4 %Y.fr)
  %Op1 = extractvalue { i4, i1 } %Agg, 1
  %ret = %Op1
```

https://alive2.llvm.org/ce/z/zgPUGT
https://alive2.llvm.org/ce/z/h2gZ_6

Note that there are cases where inserting freeze is not necessary: e.g. %Y is `noundef`.
In this case, LLVM is already good because `%ret` is already successfully folded into `and`,
triggering the pre-existing optimization in InstSimplify: https://godbolt.org/z/v6qena15K

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


Compare: https://github.com/llvm/llvm-project/compare/c58a6a6fb411...1977c53b2ae4


More information about the All-commits mailing list