diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp --- a/llvm/lib/Analysis/ValueTracking.cpp +++ b/llvm/lib/Analysis/ValueTracking.cpp @@ -2894,6 +2894,12 @@ isKnownNonZero(II->getArgOperand(1), DemandedElts, Depth, Q)) return true; break; + case Intrinsic::fshr: + case Intrinsic::fshl: + // If Op0 == Op1, this is a rotate. rotate(x, y) != 0 iff x != 0. + if (II->getArgOperand(0) == II->getArgOperand(1)) + return isKnownNonZero(II->getArgOperand(0), DemandedElts, Depth, Q); + break; case Intrinsic::vscale: return true; default: diff --git a/llvm/test/Analysis/ValueTracking/known-non-zero.ll b/llvm/test/Analysis/ValueTracking/known-non-zero.ll --- a/llvm/test/Analysis/ValueTracking/known-non-zero.ll +++ b/llvm/test/Analysis/ValueTracking/known-non-zero.ll @@ -532,10 +532,7 @@ ; CHECK-LABEL: @fshr_non_zero( ; CHECK-NEXT: [[PRED0:%.*]] = icmp ne i8 [[X:%.*]], 0 ; CHECK-NEXT: call void @llvm.assume(i1 [[PRED0]]) -; CHECK-NEXT: [[V:%.*]] = tail call i8 @llvm.fshr.i8(i8 [[X]], i8 [[X]], i8 [[Y:%.*]]) -; CHECK-NEXT: [[OR:%.*]] = or i8 [[V]], [[Z:%.*]] -; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[OR]], 0 -; CHECK-NEXT: ret i1 [[R]] +; CHECK-NEXT: ret i1 false ; %pred0 = icmp ne i8 %x, 0 call void @llvm.assume(i1 %pred0) @@ -570,10 +567,7 @@ ; CHECK-LABEL: @fshl_non_zero( ; CHECK-NEXT: [[PRED0:%.*]] = icmp ne i8 [[X:%.*]], 0 ; CHECK-NEXT: call void @llvm.assume(i1 [[PRED0]]) -; CHECK-NEXT: [[V:%.*]] = tail call i8 @llvm.fshl.i8(i8 [[X]], i8 [[X]], i8 [[Y:%.*]]) -; CHECK-NEXT: [[OR:%.*]] = or i8 [[V]], [[Z:%.*]] -; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[OR]], 0 -; CHECK-NEXT: ret i1 [[R]] +; CHECK-NEXT: ret i1 false ; %pred0 = icmp ne i8 %x, 0 call void @llvm.assume(i1 %pred0)