[LoongArch] Fix assertion when combining SETCC with wide constants (#172975)
Fixes #172964
diff --git a/llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp b/llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp
index 002883a..cf892f0 100644
--- a/llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp
+++ b/llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp
@@ -5897,10 +5897,10 @@
if (CC != ISD::SETEQ && CC != ISD::SETNE)
return SDValue();
ConstantSDNode *CN = dyn_cast<ConstantSDNode>(AndInputValue1.getOperand(1));
- if (!CN || CN->getSExtValue() != -1)
+ if (!CN || !CN->isAllOnes())
return SDValue();
CN = dyn_cast<ConstantSDNode>(CmpInputValue);
- if (!CN || CN->getSExtValue() != 0)
+ if (!CN || !CN->isZero())
return SDValue();
AndInputValue1 = AndInputValue1.getOperand(0);
if (AndInputValue1.getOpcode() != ISD::ZERO_EXTEND)
diff --git a/llvm/test/CodeGen/LoongArch/issue172964.ll b/llvm/test/CodeGen/LoongArch/issue172964.ll
new file mode 100644
index 0000000..e88eeb3
--- /dev/null
+++ b/llvm/test/CodeGen/LoongArch/issue172964.ll
@@ -0,0 +1,21 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc --mtriple=loongarch64 < %s | FileCheck %s
+
+define i1 @test(i104 %conv2, i64 %0) {
+; CHECK-LABEL: test:
+; CHECK: # %bb.0: # %entry
+; CHECK-NEXT: lu12i.w $a1, 431166
+; CHECK-NEXT: ori $a1, $a1, 1831
+; CHECK-NEXT: lu32i.d $a1, 117859
+; CHECK-NEXT: lu52i.d $a1, $a1, -335
+; CHECK-NEXT: xor $a0, $a0, $a1
+; CHECK-NEXT: and $a0, $a0, $a2
+; CHECK-NEXT: sltu $a0, $zero, $a0
+; CHECK-NEXT: ret
+entry:
+ %xor = xor i104 %conv2, 16938544400857032487
+ %conv3 = zext i64 %0 to i104
+ %and = and i104 %xor, %conv3
+ %tobool = icmp ne i104 %and, 0
+ ret i1 %tobool
+}