[llvm] 8f966ce - [SelectionDAG] Use int64_t to store the integer power of llvm.powi
Shengchen Kan via llvm-commits
llvm-commits at lists.llvm.org
Mon May 1 23:09:07 PDT 2023
Author: Shengchen Kan
Date: 2023-05-02T14:08:42+08:00
New Revision: 8f966cedea594d9a91e585e88a80a42c04049e6c
URL: https://github.com/llvm/llvm-project/commit/8f966cedea594d9a91e585e88a80a42c04049e6c
DIFF: https://github.com/llvm/llvm-project/commit/8f966cedea594d9a91e585e88a80a42c04049e6c.diff
LOG: [SelectionDAG] Use int64_t to store the integer power of llvm.powi
https://llvm.org/docs/LangRef.html#llvm-powi-intrinsic
The max length of the integer power of `llvm.powi` intrinsic is 32, and
the value can be negative. If we use `int32_t` to store this value, `-Val`
will underflow when it is `INT32_MIN`
The issue was reported in D149033.
Added:
llvm/test/CodeGen/X86/powi-int32min.ll
Modified:
llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
Removed:
################################################################################
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
index 37976337a5fd8..9d6ad1144e292 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
@@ -5451,7 +5451,7 @@ static SDValue ExpandPowI(const SDLoc &DL, SDValue LHS, SDValue RHS,
// it's beneficial on the target, otherwise we end up lowering to a call to
// __powidf2 (for example).
if (ConstantSDNode *RHSC = dyn_cast<ConstantSDNode>(RHS)) {
- int Val = RHSC->getSExtValue();
+ int64_t Val = RHSC->getSExtValue();
// powi(x, 0) -> 1.0
if (Val == 0)
diff --git a/llvm/test/CodeGen/X86/powi-int32min.ll b/llvm/test/CodeGen/X86/powi-int32min.ll
new file mode 100644
index 0000000000000..3a1304c61c49a
--- /dev/null
+++ b/llvm/test/CodeGen/X86/powi-int32min.ll
@@ -0,0 +1,17 @@
+; RUN: llc -mtriple=x86_64-unknown-unknown < %s | FileCheck %s
+
+define float @test_powi(ptr %p) nounwind {
+; CHECK-LABEL: test_powi:
+; CHECK: # %bb.0: # %bb
+; CHECK-NEXT: movss {{.*#+}} xmm1 = mem[0],zero,zero,zero
+; CHECK-COUNT-31: mulss %xmm1, %xmm1
+; CHECK-NEXT: movss {{.*#+}} xmm0 = mem[0],zero,zero,zero
+; CHECK-NEXT: divss %xmm1, %xmm0
+; CHECK-NEXT: retq
+bb:
+ %load = load float, ptr %p, align 4
+ %call = call contract float @llvm.powi.f32.i32(float %load, i32 -2147483648)
+ ret float %call
+}
+
+declare float @llvm.powi.f32.i32(float, i32)
More information about the llvm-commits
mailing list