[llvm] 8bde5f0 - [RISCV] Replace && with ||. Spotted by coverity.
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Sun Jun 6 13:25:03 PDT 2021
Author: Craig Topper
Date: 2021-06-06T13:09:51-07:00
New Revision: 8bde5f06a11d2ed30cc14b4960548d8da7a167b8
URL: https://github.com/llvm/llvm-project/commit/8bde5f06a11d2ed30cc14b4960548d8da7a167b8
DIFF: https://github.com/llvm/llvm-project/commit/8bde5f06a11d2ed30cc14b4960548d8da7a167b8.diff
LOG: [RISCV] Replace && with ||. Spotted by coverity.
We should be exiting when the shift amount is greater than
the bit width regardless of whether it is a power of 2.
Reported by Simon Pilgrim here https://reviews.llvm.org/D96661
This requires getting a shift amount that is out of bounds that
wasn't already optimized by SelectionDAG. This would be pretty
trick to construct a test for.
Or it would require a non-power of 2 shift amount and a mask
that has runs of ones and zeros of the next lowest power of 2 from
that shift amount. I tried a little to produce a test for this,
but didn't get it to work.
Added:
Modified:
llvm/lib/Target/RISCV/RISCVISelLowering.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
index 87c46893cdd4..0b2c79b2e915 100644
--- a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
+++ b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
@@ -5122,7 +5122,7 @@ matchRISCVBitmanipPat(SDValue Op, ArrayRef<uint64_t> BitmanipMasks) {
uint64_t ShAmt = Op.getConstantOperandVal(1);
unsigned Width = Op.getValueType() == MVT::i64 ? 64 : 32;
- if (ShAmt >= Width && !isPowerOf2_64(ShAmt))
+ if (ShAmt >= Width || !isPowerOf2_64(ShAmt))
return None;
// If we don't have enough masks for 64 bit, then we must be trying to
// match SHFL so we're only allowed to shift 1/4 of the width.
More information about the llvm-commits
mailing list