From: Sanjay Patel Date: Sun, 22 Aug 2021 13:13:59 +0000 (-0400) Subject: [InstSimplify] fold rotate of -1 to -1 X-Git-Tag: upstream/15.0.7~33295 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=dcf659e8219bf51e3cff4868bf75ceb7757b8210;p=platform%2Fupstream%2Fllvm.git [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 --- diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp index 9c51fe9..5536de5 100644 --- a/llvm/lib/Analysis/InstructionSimplify.cpp +++ b/llvm/lib/Analysis/InstructionSimplify.cpp @@ -5860,6 +5860,10 @@ static Value *simplifyIntrinsic(CallBase *Call, const SimplifyQuery &Q) { if (match(Op0, m_Zero()) && match(Op1, m_Zero())) return ConstantInt::getNullValue(F->getReturnType()); + // Rotating -1 by anything is -1. + if (match(Op0, m_AllOnes()) && match(Op1, m_AllOnes())) + return ConstantInt::getAllOnesValue(F->getReturnType()); + return nullptr; } case Intrinsic::experimental_constrained_fma: { diff --git a/llvm/test/Transforms/InstSimplify/call.ll b/llvm/test/Transforms/InstSimplify/call.ll index b2c6f23..a4560f8 100644 --- a/llvm/test/Transforms/InstSimplify/call.ll +++ b/llvm/test/Transforms/InstSimplify/call.ll @@ -976,8 +976,7 @@ define <2 x i8> @fshr_zero_vec(<2 x i8> %shamt) { define <2 x i7> @fshl_ones_vec(<2 x i7> %shamt) { ; CHECK-LABEL: @fshl_ones_vec( -; CHECK-NEXT: [[R:%.*]] = call <2 x i7> @llvm.fshl.v2i7(<2 x i7> , <2 x i7> , <2 x i7> [[SHAMT:%.*]]) -; CHECK-NEXT: ret <2 x i7> [[R]] +; CHECK-NEXT: ret <2 x i7> ; %r = call <2 x i7> @llvm.fshl.v2i7(<2 x i7> , <2 x i7> , <2 x i7> %shamt) ret <2 x i7> %r @@ -985,8 +984,7 @@ define <2 x i7> @fshl_ones_vec(<2 x i7> %shamt) { define i9 @fshr_ones(i9 %shamt) { ; CHECK-LABEL: @fshr_ones( -; CHECK-NEXT: [[R:%.*]] = call i9 @llvm.fshr.i9(i9 -1, i9 -1, i9 [[SHAMT:%.*]]) -; CHECK-NEXT: ret i9 [[R]] +; CHECK-NEXT: ret i9 -1 ; %r = call i9 @llvm.fshr.i9(i9 -1, i9 -1, i9 %shamt) ret i9 %r