llvm-project/llvm/lib/Transforms/InstCombine
Sanjay Patel f8962571f7 [InstCombine] try to pull 'not' of select into compare operands
not (select ?, (cmp TPred, ?, ?), (cmp FPred, ?, ?) -->
     select ?, (cmp TPred', ?, ?), (cmp FPred', ?, ?)

If both sides of the select are cmps, we can remove an instruction.
The case where only side is a cmp is deferred to a possible
follow-on patch.

We have a more general 'isFreeToInvert' analysis, but I'm not seeing
a way to use that more widely without inducing infinite looping
(opposing transforms).
Here, we flip the compare predicates directly, so we should not have
any danger by creating extra intermediate 'not' ops.

Alive proofs:
https://rise4fun.com/Alive/jKa

Name: both select values are compares - invert predicates
  %tcmp = icmp sle i32 %x, %y
  %fcmp = icmp ugt i32 %z, %w
  %sel = select i1 %cond, i1 %tcmp, i1 %fcmp
  %not = xor i1 %sel, true
=>
  %tcmp_not = icmp sgt i32 %x, %y
  %fcmp_not = icmp ule i32 %z, %w
  %not = select i1 %cond, i1 %tcmp_not, i1 %fcmp_not

Name: false val is compare - invert/not
  %fcmp = icmp ugt i32 %z, %w
  %sel = select i1 %cond, i1 %tcmp, i1 %fcmp
  %not = xor i1 %sel, true
=>
  %tcmp_not = xor i1 %tcmp, -1
  %fcmp_not = icmp ule i32 %z, %w
  %not = select i1 %cond, i1 %tcmp_not, i1 %fcmp_not

Differential Revision: https://reviews.llvm.org/D72007
2020-01-07 10:44:23 -05:00
..
CMakeLists.txt [cmake] Explicitly mark libraries defined in lib/ as "Component Libraries" 2019-11-21 10:48:08 -08:00
InstCombineAddSub.cpp [NFCI][InstCombine] Refactor 'sink negation into select if that folds one hand of select to 0' fold 2020-01-04 17:30:51 +03:00
InstCombineAndOrXor.cpp [InstCombine] try to pull 'not' of select into compare operands 2020-01-07 10:44:23 -05:00
InstCombineAtomicRMW.cpp [Alignment][NFC] Remove StoreInst::setAlignment(unsigned) 2019-10-03 13:17:21 +00:00
InstCombineCalls.cpp [X86][InstCombine] Add constant folding and simplification support for pdep and pext 2019-12-31 15:06:47 -08:00
InstCombineCasts.cpp [InstCombine] fold zext of masked bit set/clear 2019-12-31 12:35:10 -05:00
InstCombineCompares.cpp [InstCombine] replace undef elements in vector constant when doing icmp folds (PR44383) 2020-01-03 09:16:57 -05:00
InstCombineInternal.h Revert "[InstCombine] Fold PHIs with equal incoming pointers" 2019-11-14 17:42:01 +07:00
InstCombineLoadStoreAlloca.cpp [InstCombine] Teach removeBitcastsFromLoadStoreOnMinMax not to change the size of a store. 2019-12-16 12:12:54 -08:00
InstCombineMulDivRem.cpp [InstCombine] fix undef propagation for vector urem transform (PR44186) 2019-12-02 12:17:38 -05:00
InstCombinePHI.cpp [InstCombine] Don't use getFirstNonPHI in FoldIntegerTypedPHI 2019-11-14 17:52:01 -08:00
InstCombineSelect.cpp [InstCombine] Expand usub_sat patterns to handle constants 2019-11-30 16:58:01 +00:00
InstCombineShifts.cpp [InstCombine] prevent crashing/assert on shift constant expression (PR44028) 2019-11-17 17:31:09 -05:00
InstCombineSimplifyDemanded.cpp [InstCombine] Canonicalize select immediates 2019-12-19 12:36:46 +00:00
InstCombineTables.td InstCombine/AMDGPU: Add dimension-aware image intrinsics to SimplifyDemanded 2018-06-21 13:37:31 +00:00
InstCombineVectorOps.cpp [InstCombine] replace shuffle's insertelement operand if inserted scalar is not demanded 2019-12-10 10:10:05 -05:00
InstructionCombining.cpp [InstCombine] remove uses before deleting instructions (PR43723) 2020-01-02 09:47:36 -05:00
LLVMBuild.txt Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00