[llvm] [MSP430] Compute c+1 at the operand bit width in EmitCMP (PR #195892)

Byeongjee Kang via llvm-commits llvm-commits at lists.llvm.org
Tue May 5 14:04:14 PDT 2026


================
@@ -889,7 +889,7 @@ static SDValue EmitCMP(SDValue &LHS, SDValue &RHS, SDValue &TargetCC,
     // fold constant into instruction.
     if (const ConstantSDNode * C = dyn_cast<ConstantSDNode>(LHS)) {
       LHS = RHS;
-      RHS = DAG.getConstant(C->getSExtValue() + 1, dl, C->getValueType(0));
+      RHS = DAG.getConstant(C->getAPIntValue() + 1, dl, C->getValueType(0));
----------------
byeongjee wrote:

Do you mean `DAG.getSignedConstant`?

I am not entirely sure how truncation works, considering that `implicitTrunc` is `false` by default (https://github.com/llvm/llvm-project/blob/8a0c5d3f43b27c8e2895c6106d6b551d626979fd/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp#L1858)

Anyway,

When I used `DAG.getConstant(C->getZExtValue() + 1...`,
existing tests failed, including: `@fcmp_oge_f64` of `fcmp.ll`

`DAG.getSignedConstant(C->getSExtValue() + 1 ...)` seems to work fine, so I pushed a fixup commit. Please let me know how you think

https://github.com/llvm/llvm-project/pull/195892


More information about the llvm-commits mailing list