Skip to content

Commit

Permalink
[InstSimplify] fold rotate of -1 to -1
Browse files Browse the repository at this point in the history
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
  • Loading branch information
rotateright committed Aug 22, 2021
1 parent d41e308 commit dcf659e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
4 changes: 4 additions & 0 deletions llvm/lib/Analysis/InstructionSimplify.cpp
Expand Up @@ -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: {
Expand Down
6 changes: 2 additions & 4 deletions llvm/test/Transforms/InstSimplify/call.ll
Expand Up @@ -976,17 +976,15 @@ 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
}

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
Expand Down

0 comments on commit dcf659e

Please sign in to comment.