Skip to content

Commit 078eb4b

Browse files
committed
[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
1 parent 92e0c0d commit 078eb4b

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

llvm/lib/Target/RISCV/RISCVISelLowering.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3232,12 +3232,13 @@ static SDValue lowerBuildVectorOfConstants(SDValue Op, SelectionDAG &DAG,
32323232
bool Negate = false;
32333233
int64_t SplatStepVal = StepNumerator;
32343234
unsigned StepOpcode = ISD::MUL;
3235-
if (StepNumerator != 1) {
3236-
if (isPowerOf2_64(std::abs(StepNumerator))) {
3237-
Negate = StepNumerator < 0;
3238-
StepOpcode = ISD::SHL;
3239-
SplatStepVal = Log2_64(std::abs(StepNumerator));
3240-
}
3235+
// Exclude INT64_MIN to avoid passing it to std::abs. We won't optimize it
3236+
// anyway as the shift of 63 won't fit in uimm5.
3237+
if (StepNumerator != 1 && StepNumerator != INT64_MIN &&
3238+
isPowerOf2_64(std::abs(StepNumerator))) {
3239+
Negate = StepNumerator < 0;
3240+
StepOpcode = ISD::SHL;
3241+
SplatStepVal = Log2_64(std::abs(StepNumerator));
32413242
}
32423243

32433244
// Only emit VIDs with suitably-small steps/addends. We use imm5 is a

0 commit comments

Comments
 (0)