[llvm] [AMDGPU] Implement hasAndNot for scalar bitwise AND-NOT operations. (PR #112647)
Harrison Hao via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 17 23:29:28 PDT 2024
================
@@ -6822,6 +6822,84 @@ static unsigned getExtOpcodeForPromotedOp(SDValue Op) {
}
}
+SDValue SITargetLowering::combineAnd(SDValue Op, DAGCombinerInfo &DCI) const {
+ const unsigned Opc = Op.getOpcode();
+ assert(Opc == ISD::AND);
+
+ auto &DAG = DCI.DAG;
+ SDLoc DL(Op);
+
+ if (hasAndNot(Op)) {
+ SDValue LHS = Op->getOperand(0);
+ SDValue RHS = Op->getOperand(1);
+
+ // (and LHS, (or Y, ~Z))
+ if (RHS.getOpcode() == ISD::OR && RHS.hasOneUse()) {
+ SDValue Y = RHS->getOperand(0);
+ SDValue NotZ = RHS->getOperand(1);
+
+ if (NotZ.getOpcode() == ISD::XOR &&
+ isAllOnesConstant(NotZ->getOperand(1))) {
+ SDValue Z = NotZ->getOperand(0);
+
+ if (!isa<ConstantSDNode>(Y)) {
+ SDValue NotY = DAG.getNOT(DL, Y, Y.getValueType());
+ SDValue AndNotYZ =
+ DAG.getNode(ISD::AND, DL, Y.getValueType(), NotY, Z);
+ SDValue NotAndNotYZ =
+ DAG.getNOT(DL, AndNotYZ, AndNotYZ.getValueType());
+ SDValue NewAnd =
+ DAG.getNode(ISD::AND, DL, Op.getValueType(), LHS, NotAndNotYZ);
+ return NewAnd;
+ }
+ }
+ }
+ }
+
+ EVT OpTy = (Opc != ISD::SETCC) ? Op.getValueType()
----------------
harrisonGPU wrote:
Okay, I have added this feature to promoteUniformOpToI32. Thanks Shilei. :)
https://github.com/llvm/llvm-project/pull/112647
More information about the llvm-commits
mailing list