[PATCH] D142546: [ConstraintElimination] Decompose or instruction if the constant operand < 2^known_zero_bits of the first operand.

Florian Hahn via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 21 05:39:35 PST 2023


fhahn added inline comments.


================
Comment at: llvm/lib/Transforms/Scalar/ConstraintElimination.cpp:373
 
+  if (match(V, m_Or(m_Value(Op0), m_ConstantInt(CI)))) {
+    if(haveNoCommonBitsSet(Op0, CI, DL))
----------------
Could you add a comment indicating what this code does, i.e. treat or as an `Add` if no common bits are set?


================
Comment at: llvm/lib/Transforms/Scalar/ConstraintElimination.cpp:374
+  if (match(V, m_Or(m_Value(Op0), m_ConstantInt(CI)))) {
+    if(haveNoCommonBitsSet(Op0, CI, DL))
+      return MergeResults(Op0, CI, IsSigned);
----------------
nit: merge with previous if


================
Comment at: llvm/test/Transforms/ConstraintElimination/or.ll:534-535
 ; CHECK-NEXT:    [[START_4:%.*]] = or i8 [[START]], 4
 ; CHECK-NEXT:    [[T_4:%.*]] = icmp ule i8 [[START_4]], [[HIGH]]
 ; CHECK-NEXT:    call void @use(i1 [[T_4]])
 ; CHECK-NEXT:    [[START_5:%.*]] = or i8 [[START]], 5
----------------
zjaffal wrote:
> This transformation should be true
> https://alive2.llvm.org/ce/z/xvrMtA
> 
> `hasNoCommonBits` doesn't optimise it while the original implementation did
It's fine if the current version doesn't catch all possible cases we could optimize. Further improvements can be landed as follow-ups


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142546



More information about the llvm-commits mailing list