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

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 27 07:06:03 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,
----------------
nikic wrote:

As this is based on ConstantFolding APIs, maybe ConstantFolding.h may be a good place?

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


More information about the llvm-commits mailing list