[llvm] dcf659e - [InstSimplify] fold rotate of -1 to -1
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Sun Aug 22 06:22:03 PDT 2021
Author: Sanjay Patel
Date: 2021-08-22T09:15:48-04:00
New Revision: dcf659e8219bf51e3cff4868bf75ceb7757b8210
URL: https://github.com/llvm/llvm-project/commit/dcf659e8219bf51e3cff4868bf75ceb7757b8210
DIFF: https://github.com/llvm/llvm-project/commit/dcf659e8219bf51e3cff4868bf75ceb7757b8210.diff
LOG: [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
Added:
Modified:
llvm/lib/Analysis/InstructionSimplify.cpp
llvm/test/Transforms/InstSimplify/call.ll
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp
index 9c51fe9a6ae7..5536de590e1b 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 b2c6f238425a..a4560f84b6c7 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> <i7 undef, i7 -1>, <2 x i7> <i7 -1, i7 undef>, <2 x i7> [[SHAMT:%.*]])
-; CHECK-NEXT: ret <2 x i7> [[R]]
+; CHECK-NEXT: ret <2 x i7> <i7 -1, i7 -1>
;
%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)
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
More information about the llvm-commits
mailing list