From 8b04f1e49aa467b6925f4755d1f316b955958ae4 Mon Sep 17 00:00:00 2001 From: Matheus Izvekov Date: Wed, 20 Sep 2023 23:17:33 +0200 Subject: [PATCH] [X86] fix combineSubSetcc to handle a large constant (#66941) --- llvm/lib/Target/X86/X86ISelLowering.cpp | 2 +- llvm/test/CodeGen/X86/select_const_i128.ll | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 llvm/test/CodeGen/X86/select_const_i128.ll diff --git a/llvm/lib/Target/X86/X86ISelLowering.cpp b/llvm/lib/Target/X86/X86ISelLowering.cpp index 5d5040e8bac5b..81aa998d33c63 100644 --- a/llvm/lib/Target/X86/X86ISelLowering.cpp +++ b/llvm/lib/Target/X86/X86ISelLowering.cpp @@ -54221,7 +54221,7 @@ static SDValue combineSubSetcc(SDNode *N, SelectionDAG &DAG) { SDValue SetCC = Op1.getOperand(0); X86::CondCode CC = (X86::CondCode)SetCC.getConstantOperandVal(0); X86::CondCode NewCC = X86::GetOppositeBranchCondition(CC); - uint64_t NewImm = Op0C->getZExtValue() - 1; + APInt NewImm = Op0C->getAPIntValue() - 1; SDLoc DL(Op1); SDValue NewSetCC = getSETCC(NewCC, SetCC.getOperand(1), DL, DAG); NewSetCC = DAG.getNode(ISD::ZERO_EXTEND, DL, VT, NewSetCC); diff --git a/llvm/test/CodeGen/X86/select_const_i128.ll b/llvm/test/CodeGen/X86/select_const_i128.ll new file mode 100644 index 0000000000000..af38bd6ce9e3e --- /dev/null +++ b/llvm/test/CodeGen/X86/select_const_i128.ll @@ -0,0 +1,21 @@ +; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 3 +; RUN: llc < %s -mtriple=x86_64-unknown-unknown -mcpu=x86-64-v2 | FileCheck %s + +define i128 @select_eq_i128(ptr %a) { +; CHECK-LABEL: select_eq_i128: +; CHECK: # %bb.0: +; CHECK-NEXT: movdqa (%rdi), %xmm0 +; CHECK-NEXT: pxor {{\.?LCPI[0-9]+_[0-9]+}}(%rip), %xmm0 +; CHECK-NEXT: xorl %eax, %eax +; CHECK-NEXT: ptest %xmm0, %xmm0 +; CHECK-NEXT: setne %al +; CHECK-NEXT: xorl %ecx, %ecx +; CHECK-NEXT: addq $-1, %rax +; CHECK-NEXT: movabsq $9223372036854775807, %rdx # imm = 0x7FFFFFFFFFFFFFFF +; CHECK-NEXT: adcq %rcx, %rdx +; CHECK-NEXT: retq + %1 = load i128, ptr %a, align 16 + %cmp = icmp eq i128 %1, 1 + %cond = select i1 %cmp, i128 170141183460469231731687303715884105727, i128 -170141183460469231731687303715884105728 + ret i128 %cond +}