Add a pass of pointer bitcast fixes earlier (#414)
Fixes #409
* Run ReplacePointerBitcast before the first instcombine pass
* Fixes ReplacePointerBitcast to only attempt to replace valid uses
* checks users of the bitcast before making any changes
* Rewriting some tests as single pass tests
* removed equivalent end-to-end tests
diff --git a/lib/Compiler.cpp b/lib/Compiler.cpp
index 9a6b804..9963427 100644
--- a/lib/Compiler.cpp
+++ b/lib/Compiler.cpp
@@ -614,6 +614,16 @@
// %3 = load float %2
pm->add(llvm::createPromoteMemoryToRegisterPass());
+ // Try to deal with pointer bitcasts early. This can prevent problems like
+ // issue #409 where LLVM is looser about access chain addressing than SPIR-V.
+ // This needs to happen before instcombine and after replacing OpenCL
+ // builtins. This run of the pass will not handle all pointer bitcasts that
+ // could be handled. It should be run again after other optimizations (e.g
+ // InlineFuncWithPointerBitCastArgPass).
+ pm->add(clspv::createSimplifyPointerBitcastPass());
+ pm->add(clspv::createReplacePointerBitcastPass());
+ pm->add(llvm::createDeadCodeEliminationPass());
+
// Hide loads from __constant address space away from instcombine.
// This prevents us from generating select between pointers-to-__constant.
// See https://github.com/google/clspv/issues/71