Skip to content

Commit a9d7ad2

Browse files
committed
[InstCombine] Relax shamt assertion in fsh fold
Allow the result of the comparison to contain poison elements, which happens if one of the elements in the input vector is poison.
1 parent 7476b41 commit a9d7ad2

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1979,8 +1979,8 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) {
19791979
if (ModuloC != ShAmtC)
19801980
return replaceOperand(*II, 2, ModuloC);
19811981

1982-
assert(ConstantExpr::getICmp(ICmpInst::ICMP_UGT, WidthC, ShAmtC) ==
1983-
ConstantInt::getTrue(CmpInst::makeCmpResultType(Ty)) &&
1982+
assert(match(ConstantExpr::getICmp(ICmpInst::ICMP_UGT, WidthC, ShAmtC),
1983+
m_One()) &&
19841984
"Shift amount expected to be modulo bitwidth");
19851985

19861986
// Canonicalize funnel shift right by constant to funnel shift left. This

llvm/test/Transforms/InstCombine/rotate.ll

+11
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,17 @@ define <2 x i32> @rotr_v2i32_constant_nonsplat_undef0(<2 x i32> %x) {
147147
ret <2 x i32> %r
148148
}
149149

150+
define <2 x i32> @rotr_v2i32_constant_nonsplat_poison0(<2 x i32> %x) {
151+
; CHECK-LABEL: @rotr_v2i32_constant_nonsplat_poison0(
152+
; CHECK-NEXT: [[R:%.*]] = call <2 x i32> @llvm.fshl.v2i32(<2 x i32> [[X:%.*]], <2 x i32> [[X]], <2 x i32> <i32 poison, i32 19>)
153+
; CHECK-NEXT: ret <2 x i32> [[R]]
154+
;
155+
%shl = shl <2 x i32> %x, <i32 poison, i32 19>
156+
%shr = lshr <2 x i32> %x, <i32 15, i32 13>
157+
%r = or <2 x i32> %shl, %shr
158+
ret <2 x i32> %r
159+
}
160+
150161
define <2 x i32> @rotr_v2i32_constant_nonsplat_undef1(<2 x i32> %x) {
151162
; CHECK-LABEL: @rotr_v2i32_constant_nonsplat_undef1(
152163
; CHECK-NEXT: [[R:%.*]] = call <2 x i32> @llvm.fshl.v2i32(<2 x i32> [[X:%.*]], <2 x i32> [[X]], <2 x i32> <i32 17, i32 0>)

0 commit comments

Comments
 (0)