Skip to content

Commit 60bb450

Browse files
authored
[X86] LowerAsmOperandForConstraint - ensure we treat L constraint immediates as signed constants (#171098)
getTargetConstant no longer tolerates sign-extended values that can't be represented by the appropriate APInt bitwidth, which defaults to unsigned behaviour. Fixes #166058
1 parent c590b35 commit 60bb450

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

llvm/lib/Target/X86/X86ISelLowering.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61974,8 +61974,8 @@ void X86TargetLowering::LowerAsmOperandForConstraint(SDValue Op,
6197461974
if (auto *C = dyn_cast<ConstantSDNode>(Op)) {
6197561975
if (C->getZExtValue() == 0xff || C->getZExtValue() == 0xffff ||
6197661976
(Subtarget.is64Bit() && C->getZExtValue() == 0xffffffff)) {
61977-
Result = DAG.getTargetConstant(C->getSExtValue(), SDLoc(Op),
61978-
Op.getValueType());
61977+
Result = DAG.getSignedTargetConstant(C->getSExtValue(), SDLoc(Op),
61978+
Op.getValueType());
6197961979
break;
6198061980
}
6198161981
}
@@ -62013,7 +62013,8 @@ void X86TargetLowering::LowerAsmOperandForConstraint(SDValue Op,
6201362013
if (ConstantInt::isValueValidForType(Type::getInt32Ty(*DAG.getContext()),
6201462014
C->getSExtValue())) {
6201562015
// Widen to 64 bits here to get it sign extended.
62016-
Result = DAG.getTargetConstant(C->getSExtValue(), SDLoc(Op), MVT::i64);
62016+
Result =
62017+
DAG.getSignedTargetConstant(C->getSExtValue(), SDLoc(Op), MVT::i64);
6201762018
break;
6201862019
}
6201962020
// FIXME gcc accepts some relocatable values here too, but only in certain
@@ -62062,9 +62063,11 @@ void X86TargetLowering::LowerAsmOperandForConstraint(SDValue Op,
6206262063
BooleanContent BCont = getBooleanContents(MVT::i64);
6206362064
ISD::NodeType ExtOpc = IsBool ? getExtendForContent(BCont)
6206462065
: ISD::SIGN_EXTEND;
62065-
int64_t ExtVal = ExtOpc == ISD::ZERO_EXTEND ? CST->getZExtValue()
62066-
: CST->getSExtValue();
62067-
Result = DAG.getTargetConstant(ExtVal, SDLoc(Op), MVT::i64);
62066+
SDLoc DL(Op);
62067+
Result =
62068+
ExtOpc == ISD::ZERO_EXTEND
62069+
? DAG.getTargetConstant(CST->getZExtValue(), DL, MVT::i64)
62070+
: DAG.getSignedTargetConstant(CST->getSExtValue(), DL, MVT::i64);
6206862071
break;
6206962072
}
6207062073

llvm/test/CodeGen/X86/pr166058.ll

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 6
2+
; RUN: llc < %s -mtriple=x86_64-- | FileCheck %s
3+
4+
@out = global i32 0, align 4
5+
define void @bar() {
6+
; CHECK-LABEL: bar:
7+
; CHECK: # %bb.0:
8+
; CHECK-NEXT: movq out@GOTPCREL(%rip), %rax
9+
; CHECK-NEXT: #APP
10+
; CHECK-NEXT: addl $-1, (%rax)
11+
; CHECK-NEXT: #NO_APP
12+
; CHECK-NEXT: retq
13+
call void asm "addl $1,$0", "=*m,L,~{dirflag},~{fpsr},~{flags}"(ptr elementtype(i32) @out, i32 -1)
14+
ret void
15+
}

0 commit comments

Comments
 (0)