Skip to content

Commit 41d4f89

Browse files
nickdesaulnierststellar
authored andcommitted
[X86ISelLowering] permit BlockAddressSDNode "i" constraints for PIC
When building 32b x86 code as PIC, the existing handling of "i" constraints is conservative since generally we have to go through the GOT to find references to functions. But generally, BlockAddresses from C code refer to the Function in the current TU. Permit BlockAddresses to be used with the "i" constraint for those cases. I regressed this in commit 4edb998 ("[SelectionDAG] treat X constrained labels as i for asm") Fixes: #53868 Reviewed By: efriedma, MaskRay Differential Revision: https://reviews.llvm.org/D119905 (cherry picked from commit 027c16b)
1 parent d245bcf commit 41d4f89

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed

llvm/lib/Target/X86/X86ISelLowering.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54599,8 +54599,9 @@ void X86TargetLowering::LowerAsmOperandForConstraint(SDValue Op,
5459954599

5460054600
// In any sort of PIC mode addresses need to be computed at runtime by
5460154601
// adding in a register or some sort of table lookup. These can't
54602-
// be used as immediates.
54603-
if (Subtarget.isPICStyleGOT() || Subtarget.isPICStyleStubPIC())
54602+
// be used as immediates. BlockAddresses are fine though.
54603+
if ((Subtarget.isPICStyleGOT() || Subtarget.isPICStyleStubPIC()) &&
54604+
!isa<BlockAddressSDNode>(Op))
5460454605
return;
5460554606

5460654607
// If we are in non-pic codegen mode, we allow the address of a global (with

llvm/test/CodeGen/X86/inline-asm-pic.ll

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,41 @@ entry:
1818
tail call void asm "mov $1,%gs:$0", "=*m,ri,~{dirflag},~{fpsr},~{flags}"(i8** elementtype(i8*) inttoptr (i32 152 to i8**), i8* bitcast (i8** @main_q to i8*)) nounwind
1919
ret void
2020
}
21+
22+
; The intent of this test is to ensure that we handle blockaddress' correctly
23+
; with "i" constraints for -m32 -fPIC.
24+
25+
define void @x() {
26+
; CHECK-LABEL: x:
27+
; CHECK: ## %bb.0:
28+
; CHECK-NEXT: ## InlineAsm Start
29+
; CHECK-NEXT: ## Ltmp0
30+
; CHECK-EMPTY:
31+
; CHECK-NEXT: ## InlineAsm End
32+
; CHECK-NEXT: ## %bb.2: ## %return
33+
; CHECK-NEXT: retl
34+
; CHECK-NEXT: Ltmp0: ## Block address taken
35+
; CHECK-NEXT: LBB1_1: ## %overflow
36+
; CHECK-NEXT: retl
37+
callbr void asm "# ${0:l}\0A", "i"(i8* blockaddress(@x, %overflow))
38+
to label %return [label %overflow]
39+
40+
overflow:
41+
br label %return
42+
43+
return:
44+
ret void
45+
}
46+
47+
; Test unusual case of blockaddress from @x in @y's asm.
48+
define void @y() {
49+
; CHECK-LABEL: y:
50+
; CHECK: ## %bb.0:
51+
; CHECK-NEXT: ## InlineAsm Start
52+
; CHECK-NEXT: ## Ltmp0
53+
; CHECK-EMPTY:
54+
; CHECK-NEXT: ## InlineAsm End
55+
; CHECK-NEXT: retl
56+
call void asm "# ${0:l}\0A", "i"(i8* blockaddress(@x, %overflow))
57+
ret void
58+
}

0 commit comments

Comments
 (0)