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
3 changes: 3 additions & 0 deletions llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1869,6 +1869,9 @@ Instruction *InstCombinerImpl::foldCastedBitwiseLogic(BinaryOperator &I) {

// Do the logic op in the intermediate width, then widen more.
Value *NarrowLogic = Builder.CreateBinOp(LogicOpc, X, Y, I.getName());
if (auto *Disjoint = dyn_cast<PossiblyDisjointInst>(&I);
Disjoint && Disjoint->isDisjoint())
cast<PossiblyDisjointInst>(NarrowLogic)->setIsDisjoint(true);
return CastInst::Create(CastOpcode, NarrowLogic, DestTy);
}

Expand Down
54 changes: 54 additions & 0 deletions llvm/test/Transforms/InstCombine/and-xor-or.ll
Original file line number Diff line number Diff line change
Expand Up @@ -4334,6 +4334,33 @@ define i16 @or_zext_zext_2_use1(i8 %x, i8 %y) {
ret i16 %r
}

define i16 @or_disjoint_zext_zext(i8 %x, i4 %y) {
; CHECK-LABEL: define {{[^@]+}}@or_disjoint_zext_zext
; CHECK-SAME: (i8 [[X:%.*]], i4 [[Y:%.*]]) {
; CHECK-NEXT: [[TMP1:%.*]] = zext i4 [[Y]] to i8
; CHECK-NEXT: [[R1:%.*]] = or disjoint i8 [[X]], [[TMP1]]
; CHECK-NEXT: [[R:%.*]] = zext i8 [[R1]] to i16
; CHECK-NEXT: ret i16 [[R]]
;
%zx = zext i8 %x to i16
%zy = zext i4 %y to i16
%r = or disjoint i16 %zy, %zx
ret i16 %r
}

define i16 @or_disjoint_zext_zext_2(i8 %x, i8 %y) {
; CHECK-LABEL: define {{[^@]+}}@or_disjoint_zext_zext_2
; CHECK-SAME: (i8 [[X:%.*]], i8 [[Y:%.*]]) {
; CHECK-NEXT: [[R1:%.*]] = or disjoint i8 [[Y]], [[X]]
; CHECK-NEXT: [[R:%.*]] = zext i8 [[R1]] to i16
; CHECK-NEXT: ret i16 [[R]]
;
%zx = zext i8 %x to i16
%zy = zext i8 %y to i16
%r = or disjoint i16 %zy, %zx
ret i16 %r
}

define <2 x i16> @xor_zext_zext(<2 x i8> %x, <2 x i4> %y) {
; CHECK-LABEL: define {{[^@]+}}@xor_zext_zext
; CHECK-SAME: (<2 x i8> [[X:%.*]], <2 x i4> [[Y:%.*]]) {
Expand Down Expand Up @@ -4463,6 +4490,33 @@ define i16 @or_sext_sext_2_use1(i8 %x, i8 %y) {
ret i16 %r
}

define i16 @or_disjoint_sext_sext(i8 %x, i4 %y) {
; CHECK-LABEL: define {{[^@]+}}@or_disjoint_sext_sext
; CHECK-SAME: (i8 [[X:%.*]], i4 [[Y:%.*]]) {
; CHECK-NEXT: [[TMP1:%.*]] = sext i4 [[Y]] to i8
; CHECK-NEXT: [[R1:%.*]] = or disjoint i8 [[X]], [[TMP1]]
; CHECK-NEXT: [[R:%.*]] = sext i8 [[R1]] to i16
; CHECK-NEXT: ret i16 [[R]]
;
%sx = sext i8 %x to i16
%sy = sext i4 %y to i16
%r = or disjoint i16 %sx, %sy
ret i16 %r
}

define i16 @or_disjoint_sext_sext_2(i8 %x, i8 %y) {
; CHECK-LABEL: define {{[^@]+}}@or_disjoint_sext_sext_2
; CHECK-SAME: (i8 [[X:%.*]], i8 [[Y:%.*]]) {
; CHECK-NEXT: [[R1:%.*]] = or disjoint i8 [[X]], [[Y]]
; CHECK-NEXT: [[R:%.*]] = sext i8 [[R1]] to i16
; CHECK-NEXT: ret i16 [[R]]
;
%sx = sext i8 %x to i16
%sy = sext i8 %y to i16
%r = or disjoint i16 %sx, %sy
ret i16 %r
}

define i16 @xor_sext_sext(i8 %x, i4 %y) {
; CHECK-LABEL: define {{[^@]+}}@xor_sext_sext
; CHECK-SAME: (i8 [[X:%.*]], i4 [[Y:%.*]]) {
Expand Down
Loading