[PATCH] D128822: [FuncSpec] Partially revert rG8b360c69e9e3.

Alexandros Lamprineas via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 29 07:26:37 PDT 2022


labrinea created this revision.
labrinea added a reviewer: llvm-commits.
Herald added subscribers: snehasish, ormris, hiraditya.
Herald added a project: All.
labrinea requested review of this revision.
Herald added a project: LLVM.

The patch "Fix assertion failure when value is not added to solver" removed code which made the pass specialize in cases we were not intending before. The test function-specialization-constant-expression.ll explicitely mentions that in a comment.

      

When I rebase my patch https://reviews.llvm.org/D126455 on top of main I get the same assertion error when compiling this test file. Adding back the removed code fixes the problem.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D128822

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


Index: llvm/test/Transforms/FunctionSpecialization/function-specialization-constant-expression.ll
===================================================================
--- llvm/test/Transforms/FunctionSpecialization/function-specialization-constant-expression.ll
+++ llvm/test/Transforms/FunctionSpecialization/function-specialization-constant-expression.ll
@@ -10,6 +10,11 @@
 @Global = internal constant %struct {i8 0, i16 1, i32 2, i64 3, i64 4}
 
 define internal i64 @func2(i64 *%x) {
+; CHECK-LABEL: @func2(
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:    [[VAL:%.*]] = ptrtoint i64* [[X:%.*]] to i64
+; CHECK-NEXT:    ret i64 [[VAL]]
+;
 entry:
   %val = ptrtoint i64* %x to i64
   ret i64 %val
@@ -31,10 +36,10 @@
 ; CHECK-NEXT:  entry:
 ; CHECK-NEXT:    br i1 [[FLAG:%.*]], label [[PLUS:%.*]], label [[MINUS:%.*]]
 ; CHECK:       plus:
-; CHECK-NEXT:    [[TMP0:%.*]] = call i64 @func2.2(i64* getelementptr inbounds ([[STRUCT:%.*]], %struct* @Global, i32 0, i32 3))
+; CHECK-NEXT:    [[TMP0:%.*]] = call i64 @func2(i64* getelementptr inbounds ([[STRUCT:%.*]], %struct* @Global, i32 0, i32 3))
 ; CHECK-NEXT:    br label [[MERGE:%.*]]
 ; CHECK:       minus:
-; CHECK-NEXT:    [[TMP1:%.*]] = call i64 @func2.1(i64* getelementptr inbounds ([[STRUCT]], %struct* @Global, i32 0, i32 4))
+; CHECK-NEXT:    [[TMP1:%.*]] = call i64 @func2(i64* getelementptr inbounds ([[STRUCT]], %struct* @Global, i32 0, i32 4))
 ; CHECK-NEXT:    br label [[MERGE]]
 ; CHECK:       merge:
 ; CHECK-NEXT:    [[TMP2:%.*]] = phi i64 [ [[TMP0]], [[PLUS]] ], [ [[TMP1]], [[MINUS]] ]
Index: llvm/lib/Transforms/IPO/FunctionSpecialization.cpp
===================================================================
--- llvm/lib/Transforms/IPO/FunctionSpecialization.cpp
+++ llvm/lib/Transforms/IPO/FunctionSpecialization.cpp
@@ -734,6 +734,12 @@
       if (isa<PoisonValue>(V))
         return;
 
+      // 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;
+
       // TrackValueOfGlobalVariable only tracks scalar global variables.
       if (auto *GV = dyn_cast<GlobalVariable>(V)) {
         // Check if we want to specialize on the address of non-constant


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D128822.441000.patch
Type: text/x-patch
Size: 2276 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220629/4b878ed6/attachment.bin>


More information about the llvm-commits mailing list