[PATCH] D114126: [PatternMatch] Create match method to track uses complexity

Stanislav Mekhanoshin via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 17 16:05:33 PST 2021


rampitec created this revision.
rampitec added reviewers: spatel, lebedev.ri.
Herald added subscribers: dexonsmith, hiraditya.
rampitec requested review of this revision.
Herald added a project: LLVM.

This patch introduces new match function which can return
a number of matched operations with multiple uses. It also
can take an argument with a limit of such operands number
for match to succeed.

The function is needed if we want to limit a total number
of multiply used operands but not necessarily care which.

This is pilot and WIP, but this code already works. It will
need handling in many if not all matchers, but most them
will just inherit from UseTracker structure. At this point
I am positing it just for the review of the idea.

This is the test I am using with it:

  ; (c & ~(a | b)) | (b & ~(a | c)) --> ~a & (b ^ c)
  
  define i32 @or_not_and_uses(i32 %a, i32 %b, i32 %c) {
    %or1 = or i32 %a, %b
    %not1 = xor i32 %or1, -1
    %and1 = and i32 %not1, %c
  
    %or2 = or i32 %a, %c
    %not2 = xor i32 %or2, -1
    %and2 = and i32 %not2, %b
    %or3 = or i32 %and1, %and2
  
  ;  call void @use(i32 %or1)
  ;  call void @use(i32 %not1)
  ;  call void @use(i32 %and1)
  
  ;  call void @use(i32 %or2)
  ;  call void @use(i32 %not2)
  ;  call void @use(i32 %and2)
  ;  call void @use(i32 %or3)
  
    ret i32 %or3
  }
  
  declare void @use(i32)

In the above example I can uncomment any 4 @use calls for
transformation to succeed and more than 4 will prevent it.


https://reviews.llvm.org/D114126

Files:
  llvm/include/llvm/IR/PatternMatch.h
  llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D114126.388056.patch
Type: text/x-patch
Size: 5160 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211118/1ed0fd92/attachment.bin>


More information about the llvm-commits mailing list