[llvm] cae00b2 - [FuncSpec][NFC] Improve the unittest coverage for constant folding of GEPs.

Alexandros Lamprineas via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 11 05:48:04 PDT 2023


Author: Alexandros Lamprineas
Date: 2023-07-11T13:24:12+01:00
New Revision: cae00b2a9bb9eabaf71b204cea2a655c18bd51ac

URL: https://github.com/llvm/llvm-project/commit/cae00b2a9bb9eabaf71b204cea2a655c18bd51ac
DIFF: https://github.com/llvm/llvm-project/commit/cae00b2a9bb9eabaf71b204cea2a655c18bd51ac.diff

LOG: [FuncSpec][NFC] Improve the unittest coverage for constant folding of GEPs.

The InstCostVisitor is currently using the DataLayout-independent constant
folding interface. This is a workaround since we can't directly call
ConstantExpr::getGetElementPtr due to deprecation. This patch shows that
the constant folding interface we are using is not good enough.

Differential Revision: https://reviews.llvm.org/D154820

Added: 
    

Modified: 
    llvm/unittests/Transforms/IPO/FunctionSpecializationTest.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/unittests/Transforms/IPO/FunctionSpecializationTest.cpp b/llvm/unittests/Transforms/IPO/FunctionSpecializationTest.cpp
index bf65b3402f31c5..12e5d98d516203 100644
--- a/llvm/unittests/Transforms/IPO/FunctionSpecializationTest.cpp
+++ b/llvm/unittests/Transforms/IPO/FunctionSpecializationTest.cpp
@@ -225,16 +225,17 @@ TEST_F(FunctionSpecializationTest, BranchInst) {
 
 TEST_F(FunctionSpecializationTest, Misc) {
   const char *ModuleString = R"(
-    @g = constant [2 x i32] zeroinitializer, align 4
+    %struct_t = type { [8 x i16], [8 x i16], i32, i32, i32, ptr, [8 x i8] }
+    @g = constant %struct_t zeroinitializer, align 16
 
     declare i32 @llvm.smax.i32(i32, i32)
     declare i32 @bar(i32)
 
     define i32 @foo(i8 %a, i1 %cond, ptr %b, i32 %c) {
       %cmp = icmp eq i8 %a, 10
-      %ext = zext i1 %cmp to i32
-      %sel = select i1 %cond, i32 %ext, i32 1
-      %gep = getelementptr i32, ptr %b, i32 %sel
+      %ext = zext i1 %cmp to i64
+      %sel = select i1 %cond, i64 %ext, i64 1
+      %gep = getelementptr inbounds %struct_t, ptr %b, i64 %sel, i32 4
       %ld = load i32, ptr %gep
       %fr = freeze i32 %ld
       %smax = call i32 @llvm.smax.i32(i32 %fr, i32 1)
@@ -280,8 +281,8 @@ TEST_F(FunctionSpecializationTest, Misc) {
   Ref = getInstCost(Gep) + getInstCost(Load) + getInstCost(Freeze) +
         getInstCost(Smax);
   Bonus = Specializer.getSpecializationBonus(F->getArg(2), GV, Visitor);
-  EXPECT_EQ(Bonus, Ref);
-  EXPECT_TRUE(Bonus > 0);
+  EXPECT_NE(Bonus, Ref);
+  EXPECT_FALSE(Bonus > 0);
 
   Bonus = Specializer.getSpecializationBonus(F->getArg(3), Undef, Visitor);
   EXPECT_TRUE(Bonus == 0);


        


More information about the llvm-commits mailing list