[PATCH] D133449: [InstCombine] Baseline tests for folding x + (x | -x) to x & (x - 1)

Sanjay Patel via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 7 14:26:59 PDT 2022


spatel added inline comments.


================
Comment at: llvm/test/Transforms/InstCombine/add_or_sub.ll:10
+; CHECK-NEXT:    [[SUB:%.*]] = sub i32 0, [[X]]
+; CHECK-NEXT:    [[OR:%.*]] = or i32 [[X]], [[SUB]]
+; CHECK-NEXT:    [[ADD:%.*]] = add i32 [[OR]], [[X]]
----------------
This isn't the pattern you intended - notice the 'or' operands were commuted. For this test only, we don't want any extra 'thwart' instruction.


================
Comment at: llvm/test/Transforms/InstCombine/add_or_sub.ll:31-32
+  %sub = sub i8 0, %x
+  %or = or i8 %sub, %x
+  %add = add i8 %x, %or
+  ret i8 %add
----------------
This is a fun example. In order, for x to be op0 of the 'add', it must be a binop or other instruction with high complexity. But for x to be op1 of the 'or', it must be equal or lower complexity than a negate - which is treated as a special-case (lower complexity than a binop). 

Therefore, the intended pattern is impossible given the current weights. Let's just leave this test as-is in case the weightings ever change. 


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D133449/new/

https://reviews.llvm.org/D133449



More information about the llvm-commits mailing list