[PATCH] D44616: Update existed CodeGen TBAA tests

2018-03-18 Thread Danil Malyshev via Phabricator via cfe-commits
DanilM created this revision.
DanilM added reviewers: hfinkel, kosarev.
Herald added a subscriber: cfe-commits.

Just added testing of the new TBAA format to existed tests for old TBAA.


Repository:
  rC Clang

https://reviews.llvm.org/D44616

Files:
  test/CodeGen/tbaa-base.cpp
  test/CodeGen/tbaa-cast.cpp
  test/CodeGen/tbaa-class.cpp
  test/CodeGen/tbaa-for-vptr.cpp
  test/CodeGen/tbaa-ms-abi.cpp
  test/CodeGen/tbaa-reference.cpp

Index: test/CodeGen/tbaa-reference.cpp
===
--- test/CodeGen/tbaa-reference.cpp
+++ test/CodeGen/tbaa-reference.cpp
@@ -1,4 +1,5 @@
-// RUN: %clang_cc1 -triple x86_64-linux -O1 -disable-llvm-passes %s -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-linux -O1 -disable-llvm-passes %s -emit-llvm -o - | FileCheck %s  -check-prefixes=CHECK,OLD-PATH
+// RUN: %clang_cc1 -triple x86_64-linux -O1 -disable-llvm-passes %s -emit-llvm -new-struct-path-tbaa -o - | FileCheck %s -check-prefixes=CHECK,NEW-PATH
 //
 // Check that we generate correct TBAA information for reference accesses.
 
@@ -29,9 +30,16 @@
   return s;
 }
 
-// CHECK-DAG: [[TAG_pointer]] = !{[[TYPE_pointer:!.*]], [[TYPE_pointer]], i64 0}
-// CHECK-DAG: [[TAG_B_s]] = !{[[TYPE_B:!.*]], [[TYPE_pointer]], i64 0}
+// OLD-PATH-DAG: [[TAG_pointer]] = !{[[TYPE_pointer:!.*]], [[TYPE_pointer]], i64 0}
+// OLD-PATH-DAG: [[TAG_B_s]] = !{[[TYPE_B:!.*]], [[TYPE_pointer]], i64 0}
 //
-// CHECK-DAG: [[TYPE_B]] = !{!"_ZTS1B", [[TYPE_pointer]], i64 0}
-// CHECK-DAG: [[TYPE_pointer]] = !{!"any pointer", [[TYPE_char:!.*]], i64 0}
-// CHECK-DAG: [[TYPE_char]] = !{!"omnipotent char", {{!.*}}, i64 0}
+// OLD-PATH-DAG: [[TYPE_B]] = !{!"_ZTS1B", [[TYPE_pointer]], i64 0}
+// OLD-PATH-DAG: [[TYPE_pointer]] = !{!"any pointer", [[TYPE_char:!.*]], i64 0}
+// OLD-PATH-DAG: [[TYPE_char]] = !{!"omnipotent char", {{!.*}}, i64 0}
+
+// NEW-PATH-DAG: [[TAG_pointer]] = !{[[TYPE_pointer:!.*]], [[TYPE_pointer]], i64 0, i64 8}
+// NEW-PATH-DAG: [[TAG_B_s]] = !{[[TYPE_B:!.*]], [[TYPE_pointer]], i64 0, i64 8}
+//
+// NEW-PATH-DAG: [[TYPE_B]] = !{[[TYPE_char:!.*]], i64 8, !"_ZTS1B", [[TYPE_pointer]], i64 0, i64 8}
+// NEW-PATH-DAG: [[TYPE_pointer]] = !{[[TYPE_char:!.*]], i64 8, !"any pointer"}
+// NEW-PATH-DAG: [[TYPE_char]] = !{{{!.*}}, i64 1, !"omnipotent char"}
Index: test/CodeGen/tbaa-ms-abi.cpp
===
--- test/CodeGen/tbaa-ms-abi.cpp
+++ test/CodeGen/tbaa-ms-abi.cpp
@@ -1,4 +1,5 @@
-// RUN: %clang_cc1 -triple i686-pc-win32 -disable-llvm-passes -emit-llvm -o - -O1 %s | FileCheck %s
+// RUN: %clang_cc1 -triple i686-pc-win32 -disable-llvm-passes -emit-llvm -o - -O1 %s | FileCheck %s -check-prefixes=CHECK,OLD-PATH
+// RUN: %clang_cc1 -triple i686-pc-win32 -disable-llvm-passes -emit-llvm -new-struct-path-tbaa -o - -O1 %s | FileCheck %s -check-prefixes=CHECK,NEW-PATH
 //
 // Test that TBAA works in the Microsoft C++ ABI.  We used to error out while
 // attempting to mangle RTTI.
@@ -16,7 +17,11 @@
 // CHECK: store i32 42, i32* {{.*}}, !tbaa [[TAG_A_i32:!.*]]
 }
 
-// CHECK: [[TYPE_INT:!.*]] = !{!"int", [[TYPE_CHAR:!.*]], i64 0}
-// CHECK: [[TYPE_CHAR]] = !{!"omnipotent char", !
-// CHECK: [[TAG_A_i32]] = !{[[TYPE_A:!.*]], [[TYPE_INT]], i64 0}
-// CHECK: [[TYPE_A]] = !{!"?AUStructA@@", [[TYPE_INT]], i64 0}
+// OLD-PATH: [[TYPE_INT:!.*]] = !{!"int", [[TYPE_CHAR:!.*]], i64 0}
+// OLD-PATH: [[TYPE_CHAR]] = !{!"omnipotent char", !
+// OLD-PATH: [[TAG_A_i32]] = !{[[TYPE_A:!.*]], [[TYPE_INT]], i64 0}
+// OLD-PATH: [[TYPE_A]] = !{!"?AUStructA@@", [[TYPE_INT]], i64 0}
+// NEW-PATH: [[TYPE_INT:!.*]] = !{[[TYPE_CHAR:!.*]], i64 4, !"int"}
+// NEW-PATH: [[TYPE_CHAR]] = !{{{.*}}, i64 1, !"omnipotent char"}
+// NEW-PATH: [[TAG_A_i32]] = !{[[TYPE_A:!.*]], [[TYPE_INT]], i64 0, i64 4}
+// NEW-PATH: [[TYPE_A]] = !{[[TYPE_CHAR]], i64 4, !"?AUStructA@@", [[TYPE_INT]], i64 0, i64 4}
Index: test/CodeGen/tbaa-for-vptr.cpp
===
--- test/CodeGen/tbaa-for-vptr.cpp
+++ test/CodeGen/tbaa-for-vptr.cpp
@@ -1,6 +1,10 @@
-// RUN: %clang_cc1 -triple %itanium_abi_triple -emit-llvm -o - -fsanitize=thread %s | FileCheck %s
-// RUN: %clang_cc1 -triple %itanium_abi_triple -emit-llvm -o - -O1 %s | FileCheck %s
-// RUN: %clang_cc1 -triple %itanium_abi_triple -emit-llvm -o - -O1  -relaxed-aliasing -fsanitize=thread %s | FileCheck %s
+// RUN: %clang_cc1 -triple %itanium_abi_triple -emit-llvm -o - -fsanitize=thread %s | FileCheck %s --check-prefixes=CHECK,OLD-PATH
+// RUN: %clang_cc1 -triple %itanium_abi_triple -emit-llvm -o - -O1 %s | FileCheck %s --check-prefixes=CHECK,OLD-PATH
+// RUN: %clang_cc1 -triple %itanium_abi_triple -emit-llvm -o - -O1  -relaxed-aliasing -fsanitize=thread %s | FileCheck %s --check-prefixes=CHECK,OLD-PATH
+//
+// RUN: %clang_cc1 -triple %itanium_abi_triple -emit-llvm -new-struct-path-tbaa -o - -fsanitize=thread %s | FileCheck %s --check-prefixes=CHECK,NEW-PATH
+// RUN: %clang_cc1 -

[PATCH] D44617: [Transforms] Keep TBAA tags in SimplifyCFG transformations

2018-03-18 Thread Danil Malyshev via Phabricator via cfe-commits
DanilM created this revision.
DanilM added reviewers: hfinkel, rjmccall, kosarev.
Herald added a subscriber: cfe-commits.

If SimplifyCFG attaches one block to another it removes all metadata from 
instructions of a block that should be attached because it can be depended on 
conditions that are changed during transformation.
In case of TBAA metadata, it looks too conservatively: data types of load/store 
instructions cannot be changed during such transformations even if the pointed 
data was changed.
So attached the patch saves TBAA tags from removing during SimplifyCFG 
transformations.


Repository:
  rC Clang

https://reviews.llvm.org/D44617

Files:
  lib/Transforms/Utils/SimplifyCFG.cpp
  test/Transforms/SimplifyCFG/basictest.ll
  test/Transforms/SimplifyCFG/fold-two-entry-phi-tbaa.ll
  test/Transforms/SimplifyCFG/speculate-tbaa.ll

Index: test/Transforms/SimplifyCFG/speculate-tbaa.ll
===
--- test/Transforms/SimplifyCFG/speculate-tbaa.ll
+++ test/Transforms/SimplifyCFG/speculate-tbaa.ll
@@ -0,0 +1,53 @@
+; RUN: opt < %s -S -simplifycfg | FileCheck %s
+
+; This test case was generated from speculate-tbaa.c:
+;
+; void foo(int *p1, int p2, int condition) {
+;   *p1 = 100;
+;   if (condition)
+; *p1 = p2;
+; }
+;
+; using
+;   clang -cc1 -triple x86_64-linux-gnu -new-struct-path-tbaa -emit-llvm -o - -O3 -disable-llvm-passes speculate-tbaa.c | opt -mem2reg -S
+
+; ModuleID = ''
+source_filename = "speculate-tbaa.c"
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64--linux-gnu"
+
+; Function Attrs: nounwind
+define void @foo(i32* %p1, i32 %p2, i32 %condition) #0 {
+; CHECK-LABEL: @foo(
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:store i32 100, i32* %p1, align 4, !tbaa [[TBAA_Tag:![0-9]+]]
+; CHECK-NEXT:%tobool = icmp ne i32 %condition, 0
+; CHECK-NEXT:%spec.store.select = select i1 %tobool, i32 %p2, i32 100
+; CHECK-NEXT:store i32 %spec.store.select, i32* %p1, align 4, !tbaa [[TBAA_Tag]]
+entry:
+  store i32 100, i32* %p1, align 4, !tbaa !2
+  %tobool = icmp ne i32 %condition, 0
+  br i1 %tobool, label %if.then, label %if.end
+
+if.then:  ; preds = %entry
+  store i32 %p2, i32* %p1, align 4, !tbaa !2
+  br label %if.end
+
+if.end:   ; preds = %if.then, %entry
+  ret void
+}
+
+attributes #0 = { nounwind "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-features"="+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }
+
+!llvm.module.flags = !{!0}
+!llvm.ident = !{!1}
+
+; CHECK-DAG: [[TBAA_Tag]] = !{[[TBAA_Type:![0-9]+]], [[TBAA_Type]], i64 0, i64 4}
+; CHECK-DAG: [[TBAA_Type]] = !{!{{[0-9]+}}, i64 4, !"int"}
+!0 = !{i32 1, !"wchar_size", i32 4}
+!1 = !{!"clang version 7.0.0 (trunk 326065)"}
+!2 = !{!3, !3, i64 0, i64 4}
+!3 = !{!4, i64 4, !"int"}
+!4 = !{!5, i64 1, !"omnipotent char"}
+!5 = !{!"Simple C/C++ TBAA"}
+
Index: test/Transforms/SimplifyCFG/fold-two-entry-phi-tbaa.ll
===
--- test/Transforms/SimplifyCFG/fold-two-entry-phi-tbaa.ll
+++ test/Transforms/SimplifyCFG/fold-two-entry-phi-tbaa.ll
@@ -0,0 +1,75 @@
+; RUN: opt < %s -S -simplifycfg | FileCheck %s
+
+; This test case was generated from fold-two-entry-phi-tbaa.c:
+;
+; int foo(int p1, int p2, int p3) {
+;   return p1 ? p1 : p2 ? p2 : p3;
+; }
+;
+; using
+;   clang -cc1 -triple x86_64-linux-gnu -new-struct-path-tbaa -emit-llvm -o - -O3 -disable-llvm-passes fold-two-entry-phi-tbaa.c
+
+; ModuleID = 'fold-two-entry-phi-tbaa.c'
+source_filename = "fold-two-entry-phi-tbaa.c"
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64--linux-gnu"
+
+; Function Attrs: nounwind
+define i32 @foo(i32 %p1, i32 %p2, i32 %p3) #0 {
+entry:
+  %p1.addr = alloca i32, align 4
+  %p2.addr = alloca i32, align 4
+  %p3.addr = alloca i32, align 4
+  store i32 %p1, i32* %p1.addr, align 4, !tbaa !2
+  store i32 %p2, i32* %p2.addr, align 4, !tbaa !2
+  store i32 %p3, i32* %p3.addr, align 4, !tbaa !2
+  %0 = load i32, i32* %p1.addr, align 4, !tbaa !2
+  %tobool = icmp ne i32 %0, 0
+  br i1 %tobool, label %cond.true, label %cond.false
+
+cond.true:; preds = %entry
+  %1 = load i32, i32* %p1.addr, align 4, !tbaa !2
+  br label %cond.end4
+
+; CHECK: cond.false:
+; CHECK-NEXT:  %2 = load i32, i32* %p2.addr, align 4, !tbaa [[TBAA_Tag:![0-9]+]]
+; CHECK-NEXT:  %tobool1 = icmp ne i32 %2, 0
+; CHECK-NEXT:  %3 = load i32, i32* %p2.addr, align 4, !tbaa [[TBAA_Tag]]
+; CHECK-NEXT:  %4 = load i32, i32* %p3.addr, align 4, !tbaa [[TBAA_Tag]]
+; CHECK-NEXT:  %cond = select i1 %tobool

[PATCH] D44617: [Transforms] Keep TBAA tags in SimplifyCFG transformations

2018-04-05 Thread Danil Malyshev via Phabricator via cfe-commits
DanilM added a comment.

ping


Repository:
  rC Clang

https://reviews.llvm.org/D44617



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D44616: Update existed CodeGen TBAA tests

2018-04-05 Thread Danil Malyshev via Phabricator via cfe-commits
DanilM added a comment.

ping


Repository:
  rC Clang

https://reviews.llvm.org/D44616



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits