[llvm] 750247b - [ARM] Fix APInt assert for CSNEG known bits.
David Green via llvm-commits
llvm-commits at lists.llvm.org
Mon Nov 11 11:39:07 PST 2024
Author: David Green
Date: 2024-11-11T19:39:02Z
New Revision: 750247bc1cc34629a73f8311ccb87e3d7c03ae23
URL: https://github.com/llvm/llvm-project/commit/750247bc1cc34629a73f8311ccb87e3d7c03ae23
DIFF: https://github.com/llvm/llvm-project/commit/750247bc1cc34629a73f8311ccb87e3d7c03ae23.diff
LOG: [ARM] Fix APInt assert for CSNEG known bits.
Use APInt::getAllOnes(32), to avoid the assert when constructing an APInt
from -1.
Added:
Modified:
llvm/lib/Target/ARM/ARMISelLowering.cpp
llvm/test/CodeGen/Thumb2/csel.ll
Removed:
################################################################################
diff --git a/llvm/lib/Target/ARM/ARMISelLowering.cpp b/llvm/lib/Target/ARM/ARMISelLowering.cpp
index 5a72ef734e81d9..ee959cf461338c 100644
--- a/llvm/lib/Target/ARM/ARMISelLowering.cpp
+++ b/llvm/lib/Target/ARM/ARMISelLowering.cpp
@@ -20138,8 +20138,8 @@ void ARMTargetLowering::computeKnownBitsForTargetNode(const SDValue Op,
else if (Op.getOpcode() == ARMISD::CSINV)
std::swap(KnownOp1.Zero, KnownOp1.One);
else if (Op.getOpcode() == ARMISD::CSNEG)
- KnownOp1 = KnownBits::mul(
- KnownOp1, KnownBits::makeConstant(APInt(32, -1)));
+ KnownOp1 = KnownBits::mul(KnownOp1,
+ KnownBits::makeConstant(APInt::getAllOnes(32)));
Known = KnownOp0.intersectWith(KnownOp1);
break;
diff --git a/llvm/test/CodeGen/Thumb2/csel.ll b/llvm/test/CodeGen/Thumb2/csel.ll
index 137aef32a437cb..d786bc076aff9b 100644
--- a/llvm/test/CodeGen/Thumb2/csel.ll
+++ b/llvm/test/CodeGen/Thumb2/csel.ll
@@ -364,3 +364,18 @@ entry:
%t = xor i32 %s, %spec.select
ret i32 %t
}
+
+define i32 @test_known_bits(i32 %a, i32 %b) {
+; CHECK-LABEL: test_known_bits:
+; CHECK: @ %bb.0: @ %entry
+; CHECK-NEXT: movs r2, #1
+; CHECK-NEXT: cmp r0, #0
+; CHECK-NEXT: cneg r0, r2, mi
+; CHECK-NEXT: add r0, r1
+; CHECK-NEXT: bx lr
+entry:
+ %c = icmp slt i32 %a, 0
+ %s = select i1 %c, i32 -1, i32 1
+ %t = add i32 %s, %b
+ ret i32 %t
+}
More information about the llvm-commits
mailing list