[PATCH] D111567: [FuncSpec] Allow ConstExprs that are function pointers

Sjoerd Meijer via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 11 10:58:23 PDT 2021


SjoerdMeijer created this revision.
SjoerdMeijer added reviewers: ChuanqiXu, snehasish.
Herald added subscribers: ormris, hiraditya.
SjoerdMeijer requested review of this revision.
Herald added a project: LLVM.

This is a follow up of D110529 <https://reviews.llvm.org/D110529> that disallowed constexprs. That change introduced a regression as this also disallowed constexprs that are function pointers, which which is actually one of the motivating examples we do want to support.


https://reviews.llvm.org/D111567

Files:
  llvm/lib/Transforms/IPO/FunctionSpecialization.cpp
  llvm/test/Transforms/FunctionSpecialization/function-specialization-constant-expression3.ll


Index: llvm/test/Transforms/FunctionSpecialization/function-specialization-constant-expression3.ll
===================================================================
--- llvm/test/Transforms/FunctionSpecialization/function-specialization-constant-expression3.ll
+++ llvm/test/Transforms/FunctionSpecialization/function-specialization-constant-expression3.ll
@@ -4,8 +4,8 @@
 define i32 @main() {
 ; CHECK-LABEL: @main(
 ; CHECK-NEXT:  bb:
-; CHECK-NEXT:    tail call void @wombat(i8* undef, i64 undef, i64 undef, i32 (i8*, i8*)* bitcast (i32 ()* @quux to i32 (i8*, i8*)*))
-; CHECK-NEXT:    tail call void @wombat(i8* undef, i64 undef, i64 undef, i32 (i8*, i8*)* bitcast (i32 ()* @eggs to i32 (i8*, i8*)*))
+; CHECK-NEXT:    tail call void @wombat.1(i8* undef, i64 undef, i64 undef, i32 (i8*, i8*)* bitcast (i32 ()* @quux to i32 (i8*, i8*)*))
+; CHECK-NEXT:    tail call void @wombat.2(i8* undef, i64 undef, i64 undef, i32 (i8*, i8*)* bitcast (i32 ()* @eggs to i32 (i8*, i8*)*))
 ; CHECK-NEXT:    ret i32 undef
 ;
 bb:
Index: llvm/lib/Transforms/IPO/FunctionSpecialization.cpp
===================================================================
--- llvm/lib/Transforms/IPO/FunctionSpecialization.cpp
+++ llvm/lib/Transforms/IPO/FunctionSpecialization.cpp
@@ -677,8 +677,12 @@
       auto *V = CS.getArgOperand(A->getArgNo());
       if (isa<PoisonValue>(V))
         return false;
-      if (isa<ConstantExpr>(V))
-        return false;
+
+      // For now, constant expressions are fine but only if they are function
+      // calls.
+      if (auto *CE =  dyn_cast<ConstantExpr>(V))
+        if (!isa<Function>(CE->getOperand(0)))
+          return false;
 
       // TrackValueOfGlobalVariable only tracks scalar global variables.
       if (auto *GV = dyn_cast<GlobalVariable>(V)) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D111567.378736.patch
Type: text/x-patch
Size: 1788 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211011/325bb07a/attachment.bin>


More information about the llvm-commits mailing list