1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-24 03:33:20 +01:00
llvm-mirror/lib
Sanjay Patel b6de2f1d6f [InstSimplify] fold and/or of compares with equality to min/max constant
I found 12 (6 if we compress the DeMorganized forms) patterns for logic-of-compares
with a min/max constant while looking at PR45510:
https://bugs.llvm.org/show_bug.cgi?id=45510

The variations on those forms multiply the test cases by 8 (unsigned/signed, swapped
compare operands, commuted logic operands).
We have partial logic to deal with these for the unsigned min (zero) case, but
missed everything else.

We are deferring the majority of these patterns to InstCombine to allow more general
handling (see D78582).

We could use ConstantRange instead of predicate+constant matching here. I don't
expect there's any noticeable compile-time impact for either form.

Here's an abuse of Alive2 to show the 12 basic signed variants of the patterns in
one function:
http://volta.cs.utah.edu:8080/z/5Vpiyg

declare void @use(i1, i1, i1, i1, i1, i1, i1, i1, i1, i1, i1, i1)
define void @src(i8 %x, i8 %y)  {
  %m1 = icmp eq i8 %x, 127
  %c1 = icmp slt i8 %x, %y
  %r1 = and i1 %m1, %c1   ; (X == MAX) && (X < Y) --> false

  %m2 = icmp ne i8 %x, 127
  %c2 = icmp sge i8 %x, %y
  %r2 = or i1 %m2, %c2    ; (X != MAX) || (X >= Y) --> true

  %m3 = icmp eq i8 %x, -128
  %c3 = icmp sgt i8 %x, %y
  %r3 = and i1 %m3, %c3   ; (X == MIN) && (X > Y) --> false

  %m4 = icmp ne i8 %x, -128
  %c4 = icmp sle i8 %x, %y
  %r4 = or i1 %m4, %c4    ; (X != MIN) || (X <= Y) --> true

  %m5 = icmp eq i8 %x, 127
  %c5 = icmp sge i8 %x, %y
  %r5 = and i1 %m5, %c5   ; (X == MAX) && (X >= Y) --> X == MAX

  %m6 = icmp ne i8 %x, 127
  %c6 = icmp slt i8 %x, %y
  %r6 = or i1 %m6, %c6   ; (X != MAX) || (X < Y) --> X != MAX

  %m7 = icmp eq i8 %x, -128
  %c7 = icmp sle i8 %x, %y
  %r7 = and i1 %m7, %c7   ; (X == MIN) && (X <= Y) --> X == MIN

  %m8 = icmp ne i8 %x, -128
  %c8 = icmp sgt i8 %x, %y
  %r8 = or i1 %m8, %c8   ; (X != MIN) || (X > Y) --> X != MIN

  %m9 = icmp ne i8 %x, 127
  %c9 = icmp slt i8 %x, %y
  %r9 = and i1 %m9, %c9    ; (X != MAX) && (X < Y) --> X < Y

  %m10 = icmp eq i8 %x, 127
  %c10 = icmp sge i8 %x, %y
  %r10 = or i1 %m10, %c10    ; (X == MAX) || (X >= Y) --> X >= Y

  %m11 = icmp ne i8 %x, -128
  %c11 = icmp sgt i8 %x, %y
  %r11 = and i1 %m11, %c11    ; (X != MIN) && (X > Y) --> X > Y

  %m12 = icmp eq i8 %x, -128
  %c12 = icmp sle i8 %x, %y
  %r12 = or i1 %m12, %c12    ; (X == MIN) || (X <= Y) --> X <= Y

  call void @use(i1 %r1, i1 %r2, i1 %r3, i1 %r4, i1 %r5, i1 %r6, i1 %r7, i1 %r8, i1 %r9, i1 %r10, i1 %r11, i1 %r12)
  ret void
}

define void @tgt(i8 %x, i8 %y)  {
  %m5 = icmp eq i8 %x, 127
  %m6 = icmp ne i8 %x, 127
  %m7 = icmp eq i8 %x, -128
  %m8 = icmp ne i8 %x, -128
  %c9 = icmp slt i8 %x, %y
  %c10 = icmp sge i8 %x, %y
  %c11 = icmp sgt i8 %x, %y
  %c12 = icmp sle i8 %x, %y
  call void @use(i1 0, i1 1, i1 0, i1 1, i1 %m5, i1 %m6, i1 %m7, i1 %m8, i1 %c9, i1 %c10, i1 %c11, i1 %c12)
  ret void
}

Differential Revision: https://reviews.llvm.org/D78430
2020-04-23 09:16:10 -04:00
..
Analysis [InstSimplify] fold and/or of compares with equality to min/max constant 2020-04-23 09:16:10 -04:00
AsmParser [AsmParser] Remove unused forward declarations. NFC. 2020-04-22 14:01:51 +01:00
BinaryFormat XCOFF.h - replace StringRef.h include with forward declaration. NFC. 2020-04-23 13:52:48 +01:00
Bitcode [SVE] Add new VectorType subclasses 2020-04-22 08:59:01 -07:00
Bitstream
CodeGen Use FrameIndexTy for stack protector 2020-04-23 13:12:27 +01:00
DebugInfo [DebugInfo] Simplify DWARFUnit::determineStringOffsetsTableContribution(). NFC. 2020-04-22 12:11:17 +07:00
Demangle Use std::foo_t rather than std::foo in LLVM. 2020-02-11 15:12:51 -08:00
DWARFLinker [cmake] LLVMDWARFLinker - add include/llvm/DWARFLinker header path 2020-04-18 12:31:41 +01:00
ExecutionEngine RuntimeDyldELF.h - make the object namespace explicit for ELFObjectFileBase. NFC. 2020-04-23 13:52:49 +01:00
Frontend [cmake] LLVMFrontendOpenMP - fix include/llvm/Frontend/OpenMP header path 2020-04-18 12:31:39 +01:00
Fuzzer
FuzzMutate Remove CompositeType class. 2020-03-18 13:53:17 -07:00
IR [SVE] Add new VectorType subclasses 2020-04-22 08:59:01 -07:00
IRReader
LineEditor
Linker [SVE] Add new VectorType subclasses 2020-04-22 08:59:01 -07:00
LTO Enable new passmanager plugin support for LTO. 2020-04-14 15:07:07 -07:00
MC [MC][NFC] Use camelCase style for functions in MCObjectStreamer 2020-04-20 20:09:20 -07:00
MCA [MC][Bugfix] Remove redundant parameter for relaxInstruction 2020-04-21 11:06:55 +08:00
Object RecordStreamer.h - cleanup includes and forward declarations. NFC. 2020-04-22 15:07:18 +01:00
ObjectYAML [obj2yaml] - Zero initialize program headers. NFCI. 2020-04-23 12:39:14 +03:00
Option
Passes [Attributor][PM] Introduce -attributor-enable={none,cgscc,module,all} 2020-04-21 15:22:10 -05:00
ProfileData Recommit [SampleFDO] Add flag for partial profile. 2020-04-07 14:28:25 -07:00
Remarks
Support [TimeProfiler] Emit clock synchronization point 2020-04-23 01:09:31 +03:00
TableGen TGLexer.h - add missing <vector> include. 2020-04-21 11:57:10 +01:00
Target [AMDGPU] Use RegClass helper functions in getRegForInlineAsmConstraint. 2020-04-23 12:26:52 +01:00
Testing
TextAPI PR45561: Return a literal string rather than an error string to avoid returning reference to local 2020-04-15 14:27:29 -07:00
ToolDrivers
Transforms [ObjCARC] Remove unused forward declarations. NFC. 2020-04-23 13:52:49 +01:00
WindowsManifest Try to fix WindowsManifest CMake logic on Windows 2020-02-28 17:24:03 -08:00
XRay Use std::foo_t rather than std::foo in LLVM. 2020-02-11 15:12:51 -08:00
CMakeLists.txt
LLVMBuild.txt