[llvm] 078eb4b - [RISCV] Fix a UBSAN failure for passing INT64_MIN to std::abs.
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 18 12:47:58 PDT 2023
Author: Craig Topper
Date: 2023-08-18T12:47:52-07:00
New Revision: 078eb4bd85ddaac530bf2919bb32c6daa6c3e36f
URL: https://github.com/llvm/llvm-project/commit/078eb4bd85ddaac530bf2919bb32c6daa6c3e36f
DIFF: https://github.com/llvm/llvm-project/commit/078eb4bd85ddaac530bf2919bb32c6daa6c3e36f.diff
LOG: [RISCV] Fix a UBSAN failure for passing INT64_MIN to std::abs.
clang recently started checking for INT64_MIN being passed to 64-bit std::abs.
Reviewed By: MaskRay
Differential Revision: https://reviews.llvm.org/D158304
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 0e1e578ad2c0cb..6a5dde7fc3d395 100644
--- a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
+++ b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
@@ -3232,12 +3232,13 @@ static SDValue lowerBuildVectorOfConstants(SDValue Op, SelectionDAG &DAG,
bool Negate = false;
int64_t SplatStepVal = StepNumerator;
unsigned StepOpcode = ISD::MUL;
- if (StepNumerator != 1) {
- if (isPowerOf2_64(std::abs(StepNumerator))) {
- Negate = StepNumerator < 0;
- StepOpcode = ISD::SHL;
- SplatStepVal = Log2_64(std::abs(StepNumerator));
- }
+ // Exclude INT64_MIN to avoid passing it to std::abs. We won't optimize it
+ // anyway as the shift of 63 won't fit in uimm5.
+ if (StepNumerator != 1 && StepNumerator != INT64_MIN &&
+ isPowerOf2_64(std::abs(StepNumerator))) {
+ Negate = StepNumerator < 0;
+ StepOpcode = ISD::SHL;
+ SplatStepVal = Log2_64(std::abs(StepNumerator));
}
// Only emit VIDs with suitably-small steps/addends. We use imm5 is a
More information about the llvm-commits
mailing list