Skip to content

Commit 6e8b17d

Browse files
committed
[InstCombine] Support or disjoint in displaced shift fold
When I originally added this fold, it did not actually fix my motivation case, where the add was represented as an or. Now that we have the disjoint flag this can finally be cleanly supported.
1 parent 04697aa commit 6e8b17d

File tree

2 files changed

+5
-8
lines changed

2 files changed

+5
-8
lines changed

llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2127,10 +2127,10 @@ Instruction *InstCombinerImpl::foldBinOpOfDisplacedShifts(BinaryOperator &I) {
21272127
Constant *ShiftedC1, *ShiftedC2, *AddC;
21282128
Type *Ty = I.getType();
21292129
unsigned BitWidth = Ty->getScalarSizeInBits();
2130-
if (!match(&I,
2131-
m_c_BinOp(m_Shift(m_ImmConstant(ShiftedC1), m_Value(ShAmt)),
2132-
m_Shift(m_ImmConstant(ShiftedC2),
2133-
m_Add(m_Deferred(ShAmt), m_ImmConstant(AddC))))))
2130+
if (!match(&I, m_c_BinOp(m_Shift(m_ImmConstant(ShiftedC1), m_Value(ShAmt)),
2131+
m_Shift(m_ImmConstant(ShiftedC2),
2132+
m_AddLike(m_Deferred(ShAmt),
2133+
m_ImmConstant(AddC))))))
21342134
return nullptr;
21352135

21362136
// Make sure the add constant is a valid shift amount.

llvm/test/Transforms/InstCombine/binop-of-displaced-shifts.ll

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -332,10 +332,7 @@ define <2 x i8> @shl_or_non_splat_out_of_range(<2 x i8> %x) {
332332
define i8 @shl_or_with_or_disjoint_instead_of_add(i8 %x) {
333333
; CHECK-LABEL: define i8 @shl_or_with_or_disjoint_instead_of_add
334334
; CHECK-SAME: (i8 [[X:%.*]]) {
335-
; CHECK-NEXT: [[SHIFT:%.*]] = shl i8 16, [[X]]
336-
; CHECK-NEXT: [[ADD:%.*]] = or disjoint i8 [[X]], 1
337-
; CHECK-NEXT: [[SHIFT2:%.*]] = shl i8 3, [[ADD]]
338-
; CHECK-NEXT: [[BINOP:%.*]] = or i8 [[SHIFT]], [[SHIFT2]]
335+
; CHECK-NEXT: [[BINOP:%.*]] = shl i8 22, [[X]]
339336
; CHECK-NEXT: ret i8 [[BINOP]]
340337
;
341338
%shift = shl i8 16, %x

0 commit comments

Comments
 (0)