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

Alexandros Lamprineas via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 10 01:42:38 PDT 2023


labrinea created this revision.
labrinea added a reviewer: ChuanqiXu.
Herald added a subscriber: ormris.
Herald added a project: All.
labrinea requested review of this revision.
Herald added a project: LLVM.

Show that we need data-layout aware constant folding.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D154820

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


Index: llvm/unittests/Transforms/IPO/FunctionSpecializationTest.cpp
===================================================================
--- llvm/unittests/Transforms/IPO/FunctionSpecializationTest.cpp
+++ llvm/unittests/Transforms/IPO/FunctionSpecializationTest.cpp
@@ -225,16 +225,17 @@
 
 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 @@
   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);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D154820.538539.patch
Type: text/x-patch
Size: 1520 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230710/1a99afaa/attachment.bin>


More information about the llvm-commits mailing list