llvm-capstone/llvm
Sanjay Patel fae900921b [InstCombine] reduce demand-limited bool math to logic
The cmp math test is inspired by memcmp() patterns seen in D75840.
I know there's at least 1 related fold we can do here if both
values are sext'd, but I'm not seeing a way to generalize further.

We have some other bool math patterns that we want to reduce, but
that might require fixing the bogus transforms noted in D72396.

Alive proof translations of the regression tests:
https://rise4fun.com/Alive/zGWi

  Name: demand add 1
  %xz = zext i1 %x to i32
  %ys = sext i1 %y to i32
  %sub = add i32 %xz, %ys
  %r = lshr i32 %sub, 31
  =>
  %notx = xor i1 %x, 1
  %and = and i1 %y, %notx
  %r = zext i1 %and to i32

  Name: demand add 2
  %xz = zext i1 %x to i5
  %ys = sext i1 %y to i5
  %sub = add i5 %xz, %ys
  %r = and i5 %sub, 16
  =>
  %notx = xor i1 %x, 1
  %and = and i1 %y, %notx
  %r = select i1 %and, i5 -16, i5 0

  Name: demand add 3
  %xz = zext i1 %x to i8
  %ys = sext i1 %y to i8
  %a = add i8 %ys, %xz
  %r = ashr i8 %a, 7
  =>
  %notx = xor i1 %x, 1
  %and = and i1 %y, %notx
  %r = sext i1 %and to i8

  Name: cmp math
  %gt = icmp ugt i32 %x, %y
  %lt = icmp ult i32 %x, %y
  %xz = zext i1 %gt to i32
  %yz = zext i1 %lt to i32
  %s = sub i32 %xz, %yz
  %r = lshr i32 %s, 31
  =>
  %r = zext i1 %lt to i32

Differential Revision: https://reviews.llvm.org/D75961
2020-03-11 15:45:58 -04:00
..
benchmarks
bindings
cmake [clang][cmake] Include generated rst files in html built by docs-clang-html target 2020-03-05 21:30:37 -08:00
docs Fix internal links in Kaleidoscope tutorial 2020-03-09 15:07:44 -06:00
examples
include [llvm][CodeGen] IR intrinsics for SVE2 contiguous conflict detection instructions. 2020-03-11 18:28:02 +00:00
lib [InstCombine] reduce demand-limited bool math to logic 2020-03-11 15:45:58 -04:00
projects
resources
runtimes
test [InstCombine] reduce demand-limited bool math to logic 2020-03-11 15:45:58 -04:00
tools [NFC][llvm-dwarfdump] Always use 'const Twine &' 2020-03-10 12:58:59 +01:00
unittests [Object][unittest] Skip tests on machines with non-64 bit size_t 2020-03-11 15:31:30 +00:00
utils Change to individual pretty printer classes, remove generic make_printer. 2020-03-11 15:04:03 +01:00
.clang-format
.clang-tidy
.gitattributes
.gitignore
CMakeLists.txt Revert abb00753 "build: reduce CMake handling for zlib" (PR44780) 2020-03-03 11:03:09 +01:00
CODE_OWNERS.TXT
configure
CREDITS.TXT
LICENSE.TXT
llvm.spec.in
LLVMBuild.txt
README.txt
RELEASE_TESTERS.TXT

The LLVM Compiler Infrastructure
================================

This directory and its subdirectories contain source code for LLVM,
a toolkit for the construction of highly optimized compilers,
optimizers, and runtime environments.

LLVM is open source software. You may freely distribute it under the terms of
the license agreement found in LICENSE.txt.

Please see the documentation provided in docs/ for further
assistance with LLVM, and in particular docs/GettingStarted.rst for getting
started with LLVM and docs/README.txt for an overview of LLVM's
documentation setup.

If you are writing a package for LLVM, see docs/Packaging.rst for our
suggestions.