diff --git a/llvm/lib/Target/X86/X86ISelLowering.cpp b/llvm/lib/Target/X86/X86ISelLowering.cpp index b71878ae1434c..fbd875a93fd4a 100644 --- a/llvm/lib/Target/X86/X86ISelLowering.cpp +++ b/llvm/lib/Target/X86/X86ISelLowering.cpp @@ -61974,8 +61974,8 @@ void X86TargetLowering::LowerAsmOperandForConstraint(SDValue Op, if (auto *C = dyn_cast(Op)) { if (C->getZExtValue() == 0xff || C->getZExtValue() == 0xffff || (Subtarget.is64Bit() && C->getZExtValue() == 0xffffffff)) { - Result = DAG.getTargetConstant(C->getSExtValue(), SDLoc(Op), - Op.getValueType()); + Result = DAG.getSignedTargetConstant(C->getSExtValue(), SDLoc(Op), + Op.getValueType()); break; } } @@ -62013,7 +62013,8 @@ void X86TargetLowering::LowerAsmOperandForConstraint(SDValue Op, if (ConstantInt::isValueValidForType(Type::getInt32Ty(*DAG.getContext()), C->getSExtValue())) { // Widen to 64 bits here to get it sign extended. - Result = DAG.getTargetConstant(C->getSExtValue(), SDLoc(Op), MVT::i64); + Result = + DAG.getSignedTargetConstant(C->getSExtValue(), SDLoc(Op), MVT::i64); break; } // FIXME gcc accepts some relocatable values here too, but only in certain @@ -62062,9 +62063,11 @@ void X86TargetLowering::LowerAsmOperandForConstraint(SDValue Op, BooleanContent BCont = getBooleanContents(MVT::i64); ISD::NodeType ExtOpc = IsBool ? getExtendForContent(BCont) : ISD::SIGN_EXTEND; - int64_t ExtVal = ExtOpc == ISD::ZERO_EXTEND ? CST->getZExtValue() - : CST->getSExtValue(); - Result = DAG.getTargetConstant(ExtVal, SDLoc(Op), MVT::i64); + SDLoc DL(Op); + Result = + ExtOpc == ISD::ZERO_EXTEND + ? DAG.getTargetConstant(CST->getZExtValue(), DL, MVT::i64) + : DAG.getSignedTargetConstant(CST->getSExtValue(), DL, MVT::i64); break; } diff --git a/llvm/test/CodeGen/X86/pr166058.ll b/llvm/test/CodeGen/X86/pr166058.ll new file mode 100644 index 0000000000000..42d68fd0fad12 --- /dev/null +++ b/llvm/test/CodeGen/X86/pr166058.ll @@ -0,0 +1,15 @@ +; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 6 +; RUN: llc < %s -mtriple=x86_64-- | FileCheck %s + +@out = global i32 0, align 4 +define void @bar() { +; CHECK-LABEL: bar: +; CHECK: # %bb.0: +; CHECK-NEXT: movq out@GOTPCREL(%rip), %rax +; CHECK-NEXT: #APP +; CHECK-NEXT: addl $-1, (%rax) +; CHECK-NEXT: #NO_APP +; CHECK-NEXT: retq + call void asm "addl $1,$0", "=*m,L,~{dirflag},~{fpsr},~{flags}"(ptr elementtype(i32) @out, i32 -1) + ret void +}