Skip to content

Commit d41e308

Browse files
committed
[InstSimplify] fold rotate of zero to zero
This is part of solving more general rotate patterns seen in bugs related to: https://llvm.org/PR51575 https://alive2.llvm.org/ce/z/fjKwqv
1 parent a0ebac4 commit d41e308

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

llvm/lib/Analysis/InstructionSimplify.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5855,6 +5855,11 @@ static Value *simplifyIntrinsic(CallBase *Call, const SimplifyQuery &Q) {
58555855
if (ShAmtC->urem(BitWidth).isNullValue())
58565856
return Call->getArgOperand(IID == Intrinsic::fshl ? 0 : 1);
58575857
}
5858+
5859+
// Rotating zero by anything is zero.
5860+
if (match(Op0, m_Zero()) && match(Op1, m_Zero()))
5861+
return ConstantInt::getNullValue(F->getReturnType());
5862+
58585863
return nullptr;
58595864
}
58605865
case Intrinsic::experimental_constrained_fma: {

llvm/test/Transforms/InstSimplify/call.ll

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -960,17 +960,15 @@ define i9 @fshr_ops_poison6() {
960960

961961
define i8 @fshl_zero(i8 %shamt) {
962962
; CHECK-LABEL: @fshl_zero(
963-
; CHECK-NEXT: [[R:%.*]] = call i8 @llvm.fshl.i8(i8 0, i8 0, i8 [[SHAMT:%.*]])
964-
; CHECK-NEXT: ret i8 [[R]]
963+
; CHECK-NEXT: ret i8 0
965964
;
966965
%r = call i8 @llvm.fshl.i8(i8 0, i8 0, i8 %shamt)
967966
ret i8 %r
968967
}
969968

970969
define <2 x i8> @fshr_zero_vec(<2 x i8> %shamt) {
971970
; CHECK-LABEL: @fshr_zero_vec(
972-
; CHECK-NEXT: [[R:%.*]] = call <2 x i8> @llvm.fshr.v2i8(<2 x i8> zeroinitializer, <2 x i8> <i8 0, i8 undef>, <2 x i8> [[SHAMT:%.*]])
973-
; CHECK-NEXT: ret <2 x i8> [[R]]
971+
; CHECK-NEXT: ret <2 x i8> zeroinitializer
974972
;
975973
%r = call <2 x i8> @llvm.fshr.v2i8(<2 x i8> zeroinitializer, <2 x i8> <i8 0, i8 undef>, <2 x i8> %shamt)
976974
ret <2 x i8> %r

0 commit comments

Comments
 (0)