Skip to content

Commit b24f473

Browse files
committed
Fix bitwidth mismatch
Change-Id: I31eb218cdc295ccf5b2749b89945c95aed34d07f
1 parent 9e77acf commit b24f473

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3661,7 +3661,10 @@ Instruction *InstCombinerImpl::visitOr(BinaryOperator &I) {
36613661

36623662
if (LHSDecompose && RHSDecompose && LHSDecompose->X == RHSDecompose->X &&
36633663
RHSDecompose->Mask.isPowerOf2() && LHSDecompose->Mask.isPowerOf2() &&
3664-
LHSDecompose->Mask != RHSDecompose->Mask) {
3664+
LHSDecompose->Mask != RHSDecompose->Mask &&
3665+
LHSDecompose->Mask.getBitWidth() == Op0Ne->getBitWidth() &&
3666+
RHSDecompose->Mask.getBitWidth() == Op1Ne->getBitWidth()) {
3667+
assert(Op0Ne->getBitWidth() == Op1Ne->getBitWidth());
36653668
assert(ICmpInst::isEquality(LHSDecompose->Pred));
36663669
if (LHSDecompose->Pred == ICmpInst::ICMP_NE)
36673670
std::swap(Op0Eq, Op0Ne);

llvm/test/Transforms/InstCombine/or-bitmask.ll

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,44 @@ define <2 x i32> @add_select_cmp_vec_nonunique(<2 x i32> %in) {
323323
%out = or disjoint <2 x i32> %sel0, %sel1
324324
ret <2 x i32> %out
325325
}
326+
327+
define i64 @mask_select_types(i32 %in) {
328+
; CHECK-LABEL: @mask_select_types(
329+
; CHECK-NEXT: [[BITOP0:%.*]] = and i32 [[IN:%.*]], 1
330+
; CHECK-NEXT: [[CMP0_NOT:%.*]] = icmp eq i32 [[BITOP0]], 0
331+
; CHECK-NEXT: [[BITOP1:%.*]] = and i32 [[IN]], 2
332+
; CHECK-NEXT: [[CMP1_NOT:%.*]] = icmp eq i32 [[BITOP1]], 0
333+
; CHECK-NEXT: [[SEL0:%.*]] = select i1 [[CMP0_NOT]], i64 0, i64 72
334+
; CHECK-NEXT: [[SEL1:%.*]] = select i1 [[CMP1_NOT]], i64 0, i64 144
335+
; CHECK-NEXT: [[OUT:%.*]] = or disjoint i64 [[SEL0]], [[SEL1]]
336+
; CHECK-NEXT: ret i64 [[OUT]]
337+
;
338+
%bitop0 = and i32 %in, 1
339+
%cmp0 = icmp ne i32 %bitop0, 0
340+
%bitop1 = and i32 %in, 2
341+
%cmp1 = icmp ne i32 %bitop1, 0
342+
%sel0 = select i1 %cmp0, i64 72, i64 0
343+
%sel1 = select i1 %cmp1, i64 144, i64 0
344+
%out = or disjoint i64 %sel0, %sel1
345+
ret i64 %out
346+
}
347+
348+
define i64 @mask_select_types_1(i64 %in) {
349+
; CHECK-LABEL: @mask_select_types_1(
350+
; CHECK-NEXT: [[TMP1:%.*]] = and i64 [[IN:%.*]], 3
351+
; CHECK-NEXT: [[OUT:%.*]] = mul nuw nsw i64 [[TMP1]], 72
352+
; CHECK-NEXT: ret i64 [[OUT]]
353+
;
354+
%bitop0 = and i64 %in, 1
355+
%cmp0 = icmp ne i64 %bitop0, 0
356+
%bitop1 = and i64 %in, 2
357+
%cmp1 = icmp ne i64 %bitop1, 0
358+
%sel0 = select i1 %cmp0, i64 72, i64 0
359+
%sel1 = select i1 %cmp1, i64 144, i64 0
360+
%out = or disjoint i64 %sel0, %sel1
361+
ret i64 %out
362+
}
363+
326364
;; NOTE: These prefixes are unused and the list is autogenerated. Do not add tests below this line:
327365
; CONSTSPLAT: {{.*}}
328366
; CONSTVEC: {{.*}}

0 commit comments

Comments
 (0)