[llvm] b20a1d8 - GVNSink: Allow handling addrspacecast

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 23 13:51:14 PDT 2020


Author: Matt Arsenault
Date: 2020-03-23T16:50:58-04:00
New Revision: b20a1d840f0c074514a71c80bbb41702a0b86d64

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

LOG: GVNSink: Allow handling addrspacecast

Added: 
    

Modified: 
    llvm/lib/Transforms/Scalar/GVNSink.cpp
    llvm/test/Transforms/GVNSink/sink-common-code.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Scalar/GVNSink.cpp b/llvm/lib/Transforms/Scalar/GVNSink.cpp
index 6d0a4975e266..6b9a88d04eda 100644
--- a/llvm/lib/Transforms/Scalar/GVNSink.cpp
+++ b/llvm/lib/Transforms/Scalar/GVNSink.cpp
@@ -475,6 +475,7 @@ class ValueTable {
     case Instruction::PtrToInt:
     case Instruction::IntToPtr:
     case Instruction::BitCast:
+    case Instruction::AddrSpaceCast:
     case Instruction::Select:
     case Instruction::ExtractElement:
     case Instruction::InsertElement:

diff  --git a/llvm/test/Transforms/GVNSink/sink-common-code.ll b/llvm/test/Transforms/GVNSink/sink-common-code.ll
index 02b1eb7fe259..160bbd370ff5 100644
--- a/llvm/test/Transforms/GVNSink/sink-common-code.ll
+++ b/llvm/test/Transforms/GVNSink/sink-common-code.ll
@@ -692,6 +692,73 @@ if.end:
 ; CHECK-NOT: exact
 ; CHECK: }
 
+
+; CHECK-LABEL: @common_bitcast(
+; CHECK: %. = select i1 %flag, float 2.000000e+00, float 1.000000e+00
+; CHECK: %a = bitcast i32* %x to float*
+; CHECK: store float %., float* %a
+define i32 @common_bitcast(i1 zeroext %flag, i32* %x) {
+entry:
+  br i1 %flag, label %if.then, label %if.else
+
+if.then:
+  %a = bitcast i32* %x to float*
+  store float 2.0, float* %a
+  br label %if.end
+
+if.else:
+  %b = bitcast i32* %x to float*
+  store float 1.0, float* %b
+  br label %if.end
+
+if.end:
+  ret i32 1
+}
+
+; CHECK-LABEL: @common_addrspacecast(
+; CHECK: %. = select i1 %flag, i32 9, i32 10
+; CHECK: %a = addrspacecast i32* %x to i32 addrspace(1)*
+; CHECK: store i32 %., i32 addrspace(1)* %a
+define i32 @common_addrspacecast(i1 zeroext %flag, i32* %x) {
+entry:
+  br i1 %flag, label %if.then, label %if.else
+
+if.then:
+  %a = addrspacecast i32* %x to i32 addrspace(1)*
+  store i32 9, i32 addrspace(1)* %a
+  br label %if.end
+
+if.else:
+  %b = addrspacecast i32* %x to i32 addrspace(1)*
+  store i32 10, i32 addrspace(1)* %b
+  br label %if.end
+
+if.end:
+  ret i32 1
+}
+
+; Don't merge 
diff erent address spaces
+; CHECK-LABEL: @no_common_addrspacecast(
+; CHECK: addrspacecast i32* %x to i32 addrspace(1)*
+; CHECK: addrspacecast i32* %x to i32 addrspace(3)*
+define i32 @no_common_addrspacecast(i1 zeroext %flag, i32* %x) {
+entry:
+  br i1 %flag, label %if.then, label %if.else
+
+if.then:
+  %a = addrspacecast i32* %x to i32 addrspace(1)*
+  store i32 9, i32 addrspace(1)* %a
+  br label %if.end
+
+if.else:
+  %b = addrspacecast i32* %x to i32 addrspace(3)*
+  store i32 10, i32 addrspace(3)* %b
+  br label %if.end
+
+if.end:
+  ret i32 1
+}
+
 ; CHECK: !0 = !{!1, !1, i64 0}
 ; CHECK: !1 = !{!"float", !2}
 ; CHECK: !2 = !{!"an example type tree"}


        


More information about the llvm-commits mailing list