Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions llvm/lib/Target/RISCV/RISCVISelLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16112,6 +16112,13 @@ static SDValue combineXorToBitfieldInsert(SDNode *N, SelectionDAG &DAG,
m_Value(Inserted))))))
return SDValue();

KnownBits Known = DAG.computeKnownBits(Inserted);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use DAG.MaskedValueIsZero(Inserted, ~CMask)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


// Check if all zero bits in CMask are also zero in Inserted
APInt CMaskZeroBits = ~CMask;
if (!CMaskZeroBits.isSubsetOf(Known.Zero))
return SDValue();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Computing known bits is much more difficult than e.g. looking at the value type or checking if something is a shifted mask. Can you re-order this check to after the other two checks for efficiency?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved it.


if (N->getValueType(0) != MVT::i32)
return SDValue();

Expand Down
21 changes: 21 additions & 0 deletions llvm/test/CodeGen/RISCV/xqcibm-insbi.ll
Original file line number Diff line number Diff line change
Expand Up @@ -170,3 +170,24 @@ define i64 @insb_i64(i64 %in1, i64 %in2) {
%xor2 = xor i64 %xor1, %in1
ret i64 %xor2
}

define i8 @tgt2_insb_neg(i8 %x, i8 %y) {
; RV32I-LABEL: tgt2_insb_neg:
; RV32I: # %bb.0:
; RV32I-NEXT: andi a2, a0, -2
; RV32I-NEXT: xor a0, a0, a1
; RV32I-NEXT: xor a0, a0, a2
; RV32I-NEXT: ret
;
; RV32XQCIBM-LABEL: tgt2_insb_neg:
; RV32XQCIBM: # %bb.0:
; RV32XQCIBM-NEXT: andi a2, a0, -2
; RV32XQCIBM-NEXT: xor a0, a0, a1
; RV32XQCIBM-NEXT: xor a0, a0, a2
; RV32XQCIBM-NEXT: ret
%and = and i8 %x, -2
%xor1 = xor i8 %and, %y
%xor2 = xor i8 %x, %xor1
ret i8 %xor2
}