[llvm] [VectorCombine] Support pattern `bitop(cast(x), C) -> cast(bitop(x, InvC))` (PR #155216)

via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 25 05:28:20 PDT 2025


================
@@ -929,6 +930,158 @@ bool VectorCombine::foldBitOpOfCastops(Instruction &I) {
   return true;
 }
 
+struct PreservedCastFlags {
+  bool NNeg = false;
+  bool NUW = false;
+  bool NSW = false;
+};
+
+// Try to cast C to InvC losslessly, satisfying CastOp(InvC) == C.
+// Will try best to preserve the flags.
+static Constant *getLosslessInvCast(Constant *C, Type *InvCastTo,
----------------
XChy wrote:

Yes, it's possible to extract this as a public API, but I am not sure `InstCombineInternal.h` is a good place. Maybe `InstructionSimplify.h` is more proper.
And by this API, we can extend `foldLogicCastConstant` in InstCombine. Anyway, I would refactor and extend in a new patch.

https://github.com/llvm/llvm-project/pull/155216


More information about the llvm-commits mailing list