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
5 changes: 4 additions & 1 deletion llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,10 @@ Instruction *InstCombinerImpl::commonShiftTransforms(BinaryOperator &I) {
return R;

Constant *CUI;
if (match(Op1, m_ImmConstant(CUI)))
if (match(Op1, m_Constant(CUI)) &&
(!isa<ConstantExpr>(CUI) ||
Copy link
Member

Choose a reason for hiding this comment

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

Can you add a fixme here to note that we should remove this special case after we use ConstantInt to represent a scalable vector splat by default?

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 in the matcher for a0f4ac6

(Ty->isVectorTy() &&
isa_and_present<ConstantInt>(CUI->getSplatValue()))))
if (Instruction *Res = FoldShiftByConstant(Op0, CUI, I))
return Res;

Expand Down
11 changes: 11 additions & 0 deletions llvm/test/Transforms/InstCombine/shl-bo.ll
Original file line number Diff line number Diff line change
Expand Up @@ -656,3 +656,14 @@ define <16 x i8> @test_FoldShiftByConstant_CreateAnd(<16 x i8> %in0) {
%vshl_n = shl <16 x i8> %tmp, <i8 5, i8 5, i8 5, i8 5, i8 5, i8 5, i8 5, i8 5, i8 5, i8 5, i8 5, i8 5, i8 5, i8 5, i8 5, i8 5>
ret <16 x i8> %vshl_n
}

define <vscale x 1 x i8> @test_FoldShiftByConstant_CreateAnd_scalable(<vscale x 1 x i8> %x) {
; CHECK-LABEL: @test_FoldShiftByConstant_CreateAnd_scalable(
; CHECK-NEXT: [[TMP1:%.*]] = shl <vscale x 1 x i8> [[X:%.*]], splat (i8 2)
; CHECK-NEXT: [[TMP2:%.*]] = and <vscale x 1 x i8> [[TMP1]], splat (i8 8)
; CHECK-NEXT: ret <vscale x 1 x i8> [[TMP2]]
;
%1 = and <vscale x 1 x i8> %x, splat (i8 2)
%2 = shl <vscale x 1 x i8> %1, splat (i8 2)
ret <vscale x 1 x i8> %2
}
11 changes: 11 additions & 0 deletions llvm/test/Transforms/InstCombine/shl-twice-constant.ll
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,14 @@ define i64 @testfunc() {
%shl2 = shl i64 %shl1, ptrtoint (ptr @c to i64)
ret i64 %shl2
}

define <vscale x 1 x i64> @scalable() {
; CHECK-LABEL: @scalable(
; CHECK-NEXT: [[SHL1:%.*]] = shl nuw <vscale x 1 x i64> splat (i64 1), shufflevector (<vscale x 1 x i64> insertelement (<vscale x 1 x i64> poison, i64 ptrtoint (ptr @c2 to i64), i64 0), <vscale x 1 x i64> poison, <vscale x 1 x i32> zeroinitializer)
; CHECK-NEXT: [[SHL2:%.*]] = shl <vscale x 1 x i64> [[SHL1]], shufflevector (<vscale x 1 x i64> insertelement (<vscale x 1 x i64> poison, i64 ptrtoint (ptr @c to i64), i64 0), <vscale x 1 x i64> poison, <vscale x 1 x i32> zeroinitializer)
; CHECK-NEXT: ret <vscale x 1 x i64> [[SHL2]]
;
%shl1 = shl <vscale x 1 x i64> splat (i64 1), splat (i64 ptrtoint (ptr @c2 to i64))
%shl2 = shl <vscale x 1 x i64> %shl1, splat (i64 ptrtoint (ptr @c to i64))
ret <vscale x 1 x i64> %shl2
}