Skip to content

Commit dcf659e

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

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

llvm/lib/Analysis/InstructionSimplify.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5860,6 +5860,10 @@ static Value *simplifyIntrinsic(CallBase *Call, const SimplifyQuery &Q) {
58605860
if (match(Op0, m_Zero()) && match(Op1, m_Zero()))
58615861
return ConstantInt::getNullValue(F->getReturnType());
58625862

5863+
// Rotating -1 by anything is -1.
5864+
if (match(Op0, m_AllOnes()) && match(Op1, m_AllOnes()))
5865+
return ConstantInt::getAllOnesValue(F->getReturnType());
5866+
58635867
return nullptr;
58645868
}
58655869
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
@@ -976,17 +976,15 @@ define <2 x i8> @fshr_zero_vec(<2 x i8> %shamt) {
976976

977977
define <2 x i7> @fshl_ones_vec(<2 x i7> %shamt) {
978978
; CHECK-LABEL: @fshl_ones_vec(
979-
; CHECK-NEXT: [[R:%.*]] = call <2 x i7> @llvm.fshl.v2i7(<2 x i7> <i7 undef, i7 -1>, <2 x i7> <i7 -1, i7 undef>, <2 x i7> [[SHAMT:%.*]])
980-
; CHECK-NEXT: ret <2 x i7> [[R]]
979+
; CHECK-NEXT: ret <2 x i7> <i7 -1, i7 -1>
981980
;
982981
%r = call <2 x i7> @llvm.fshl.v2i7(<2 x i7> <i7 undef, i7 -1>, <2 x i7> <i7 -1, i7 undef>, <2 x i7> %shamt)
983982
ret <2 x i7> %r
984983
}
985984

986985
define i9 @fshr_ones(i9 %shamt) {
987986
; CHECK-LABEL: @fshr_ones(
988-
; CHECK-NEXT: [[R:%.*]] = call i9 @llvm.fshr.i9(i9 -1, i9 -1, i9 [[SHAMT:%.*]])
989-
; CHECK-NEXT: ret i9 [[R]]
987+
; CHECK-NEXT: ret i9 -1
990988
;
991989
%r = call i9 @llvm.fshr.i9(i9 -1, i9 -1, i9 %shamt)
992990
ret i9 %r

0 commit comments

Comments
 (0)