Merge pull request #1762 from jeffbolznv/issue1760

For nonuniformEXT constructor, make a copy of the node to decorate
diff --git a/SPIRV/GlslangToSpv.cpp b/SPIRV/GlslangToSpv.cpp
index 25ef210..655d77b 100644
--- a/SPIRV/GlslangToSpv.cpp
+++ b/SPIRV/GlslangToSpv.cpp
@@ -5543,6 +5543,11 @@
     case glslang::EOpConstructReference:
         unaryOp = spv::OpBitcast;
         break;
+
+    case glslang::EOpCopyObject:
+        unaryOp = spv::OpCopyObject;
+        break;
+
     default:
         return 0;
     }
diff --git a/Test/baseResults/nonuniform.frag.out b/Test/baseResults/nonuniform.frag.out
index 2d4e9b0..0df8cfc 100644
--- a/Test/baseResults/nonuniform.frag.out
+++ b/Test/baseResults/nonuniform.frag.out
@@ -31,11 +31,13 @@
 0:27      move second child to first child ( temp int)
 0:27        'nu_li' ( nonuniform temp int)
 0:27        add ( nonuniform temp int)
-0:27          'a' ( nonuniform temp int)
-0:27          component-wise multiply ( nonuniform temp int)
+0:27          copy object ( nonuniform temp int)
 0:27            'a' ( temp int)
-0:27            Constant:
-0:27              2 (const int)
+0:27          copy object ( nonuniform temp int)
+0:27            component-wise multiply ( temp int)
+0:27              'a' ( temp int)
+0:27              Constant:
+0:27                2 (const int)
 0:28      'nu_li' ( nonuniform temp int)
 0:29      'nu_li' ( nonuniform temp int)
 0:?   Linker Objects
@@ -72,11 +74,13 @@
 0:27      move second child to first child ( temp int)
 0:27        'nu_li' ( nonuniform temp int)
 0:27        add ( nonuniform temp int)
-0:27          'a' ( nonuniform temp int)
-0:27          component-wise multiply ( nonuniform temp int)
+0:27          copy object ( nonuniform temp int)
 0:27            'a' ( temp int)
-0:27            Constant:
-0:27              2 (const int)
+0:27          copy object ( nonuniform temp int)
+0:27            component-wise multiply ( temp int)
+0:27              'a' ( temp int)
+0:27              Constant:
+0:27                2 (const int)
 0:28      'nu_li' ( nonuniform temp int)
 0:29      'nu_li' ( nonuniform temp int)
 0:?   Linker Objects
diff --git a/Test/baseResults/spv.nonuniform.frag.out b/Test/baseResults/spv.nonuniform.frag.out
index 972276a..f30acc9 100644
--- a/Test/baseResults/spv.nonuniform.frag.out
+++ b/Test/baseResults/spv.nonuniform.frag.out
@@ -1,7 +1,7 @@
 spv.nonuniform.frag
 // Module Version 10000
 // Generated by (magic number): 80007
-// Id's are bound by 210
+// Id's are bound by 212
 
                               Capability Shader
                               Capability InputAttachment
@@ -22,7 +22,7 @@
                               Extension  "SPV_EXT_descriptor_indexing"
                1:             ExtInstImport  "GLSL.std.450"
                               MemoryModel Logical GLSL450
-                              EntryPoint Fragment 4  "main" 33 90
+                              EntryPoint Fragment 4  "main" 35 92
                               ExecutionMode 4 OriginUpperLeft
                               Source GLSL 450
                               SourceExtension  "GL_EXT_nonuniform_qualifier"
@@ -34,189 +34,189 @@
                               Name 17  "nu_li"
                               Name 18  "param"
                               Name 20  "param"
-                              Name 30  "b"
-                              Name 33  "nu_inv4"
-                              Name 39  "nu_gf"
-                              Name 45  "inputAttachmentDyn"
-                              Name 46  "dyn_i"
-                              Name 62  "uniformTexelBufferDyn"
-                              Name 76  "storageTexelBufferDyn"
-                              Name 85  "uname"
-                              MemberName 85(uname) 0  "a"
-                              Name 88  "uniformBuffer"
-                              Name 90  "nu_ii"
-                              Name 97  "bname"
-                              MemberName 97(bname) 0  "b"
-                              Name 100  "storageBuffer"
-                              Name 110  "sampledImage"
-                              Name 125  "storageImage"
-                              Name 137  "inputAttachment"
-                              Name 147  "uniformTexelBuffer"
-                              Name 158  "storageTexelBuffer"
-                              Name 168  "v"
-                              Name 183  "uv"
-                              Name 193  "m"
-                              Name 201  "S"
-                              MemberName 201(S) 0  "a"
-                              Name 203  "s"
+                              Name 32  "b"
+                              Name 35  "nu_inv4"
+                              Name 41  "nu_gf"
+                              Name 47  "inputAttachmentDyn"
+                              Name 48  "dyn_i"
+                              Name 64  "uniformTexelBufferDyn"
+                              Name 78  "storageTexelBufferDyn"
+                              Name 87  "uname"
+                              MemberName 87(uname) 0  "a"
+                              Name 90  "uniformBuffer"
+                              Name 92  "nu_ii"
+                              Name 99  "bname"
+                              MemberName 99(bname) 0  "b"
+                              Name 102  "storageBuffer"
+                              Name 112  "sampledImage"
+                              Name 127  "storageImage"
+                              Name 139  "inputAttachment"
+                              Name 149  "uniformTexelBuffer"
+                              Name 160  "storageTexelBuffer"
+                              Name 170  "v"
+                              Name 185  "uv"
+                              Name 195  "m"
+                              Name 203  "S"
+                              MemberName 203(S) 0  "a"
+                              Name 205  "s"
                               Decorate 13 DecorationNonUniformEXT
                               Decorate 17(nu_li) DecorationNonUniformEXT
                               Decorate 19 DecorationNonUniformEXT
-                              Decorate 23 DecorationNonUniformEXT
-                              Decorate 26 DecorationNonUniformEXT
-                              Decorate 27 DecorationNonUniformEXT
-                              Decorate 33(nu_inv4) Location 0
-                              Decorate 33(nu_inv4) DecorationNonUniformEXT
-                              Decorate 38 DecorationNonUniformEXT
-                              Decorate 39(nu_gf) DecorationNonUniformEXT
+                              Decorate 24 DecorationNonUniformEXT
+                              Decorate 28 DecorationNonUniformEXT
+                              Decorate 29 DecorationNonUniformEXT
+                              Decorate 35(nu_inv4) Location 0
+                              Decorate 35(nu_inv4) DecorationNonUniformEXT
                               Decorate 40 DecorationNonUniformEXT
-                              Decorate 41 DecorationNonUniformEXT
-                              Decorate 45(inputAttachmentDyn) DescriptorSet 0
-                              Decorate 45(inputAttachmentDyn) Binding 0
-                              Decorate 45(inputAttachmentDyn) InputAttachmentIndex 0
-                              Decorate 62(uniformTexelBufferDyn) DescriptorSet 0
-                              Decorate 62(uniformTexelBufferDyn) Binding 1
-                              Decorate 76(storageTexelBufferDyn) DescriptorSet 0
-                              Decorate 76(storageTexelBufferDyn) Binding 2
-                              MemberDecorate 85(uname) 0 Offset 0
-                              Decorate 85(uname) Block
-                              Decorate 88(uniformBuffer) DescriptorSet 0
-                              Decorate 88(uniformBuffer) Binding 3
-                              Decorate 90(nu_ii) Flat
-                              Decorate 90(nu_ii) Location 1
-                              Decorate 90(nu_ii) DecorationNonUniformEXT
-                              Decorate 91 DecorationNonUniformEXT
-                              Decorate 94 DecorationNonUniformEXT
-                              MemberDecorate 97(bname) 0 Offset 0
-                              Decorate 97(bname) BufferBlock
-                              Decorate 100(storageBuffer) DescriptorSet 0
-                              Decorate 100(storageBuffer) Binding 4
-                              Decorate 101 DecorationNonUniformEXT
+                              Decorate 41(nu_gf) DecorationNonUniformEXT
+                              Decorate 42 DecorationNonUniformEXT
+                              Decorate 43 DecorationNonUniformEXT
+                              Decorate 47(inputAttachmentDyn) DescriptorSet 0
+                              Decorate 47(inputAttachmentDyn) Binding 0
+                              Decorate 47(inputAttachmentDyn) InputAttachmentIndex 0
+                              Decorate 64(uniformTexelBufferDyn) DescriptorSet 0
+                              Decorate 64(uniformTexelBufferDyn) Binding 1
+                              Decorate 78(storageTexelBufferDyn) DescriptorSet 0
+                              Decorate 78(storageTexelBufferDyn) Binding 2
+                              MemberDecorate 87(uname) 0 Offset 0
+                              Decorate 87(uname) Block
+                              Decorate 90(uniformBuffer) DescriptorSet 0
+                              Decorate 90(uniformBuffer) Binding 3
+                              Decorate 92(nu_ii) Flat
+                              Decorate 92(nu_ii) Location 1
+                              Decorate 92(nu_ii) DecorationNonUniformEXT
+                              Decorate 93 DecorationNonUniformEXT
+                              Decorate 96 DecorationNonUniformEXT
+                              MemberDecorate 99(bname) 0 Offset 0
+                              Decorate 99(bname) BufferBlock
+                              Decorate 102(storageBuffer) DescriptorSet 0
+                              Decorate 102(storageBuffer) Binding 4
                               Decorate 103 DecorationNonUniformEXT
-                              Decorate 110(sampledImage) DescriptorSet 0
-                              Decorate 110(sampledImage) Binding 5
-                              Decorate 111 DecorationNonUniformEXT
-                              Decorate 114 DecorationNonUniformEXT
-                              Decorate 125(storageImage) DescriptorSet 0
-                              Decorate 125(storageImage) Binding 6
-                              Decorate 126 DecorationNonUniformEXT
-                              Decorate 129 DecorationNonUniformEXT
-                              Decorate 137(inputAttachment) DescriptorSet 0
-                              Decorate 137(inputAttachment) Binding 7
-                              Decorate 137(inputAttachment) InputAttachmentIndex 1
-                              Decorate 138 DecorationNonUniformEXT
+                              Decorate 105 DecorationNonUniformEXT
+                              Decorate 112(sampledImage) DescriptorSet 0
+                              Decorate 112(sampledImage) Binding 5
+                              Decorate 113 DecorationNonUniformEXT
+                              Decorate 116 DecorationNonUniformEXT
+                              Decorate 127(storageImage) DescriptorSet 0
+                              Decorate 127(storageImage) Binding 6
+                              Decorate 128 DecorationNonUniformEXT
+                              Decorate 131 DecorationNonUniformEXT
+                              Decorate 139(inputAttachment) DescriptorSet 0
+                              Decorate 139(inputAttachment) Binding 7
+                              Decorate 139(inputAttachment) InputAttachmentIndex 1
                               Decorate 140 DecorationNonUniformEXT
-                              Decorate 147(uniformTexelBuffer) DescriptorSet 0
-                              Decorate 147(uniformTexelBuffer) Binding 8
-                              Decorate 148 DecorationNonUniformEXT
+                              Decorate 142 DecorationNonUniformEXT
+                              Decorate 149(uniformTexelBuffer) DescriptorSet 0
+                              Decorate 149(uniformTexelBuffer) Binding 8
                               Decorate 150 DecorationNonUniformEXT
-                              Decorate 158(storageTexelBuffer) DescriptorSet 0
-                              Decorate 158(storageTexelBuffer) Binding 9
-                              Decorate 159 DecorationNonUniformEXT
+                              Decorate 152 DecorationNonUniformEXT
+                              Decorate 160(storageTexelBuffer) DescriptorSet 0
+                              Decorate 160(storageTexelBuffer) Binding 9
                               Decorate 161 DecorationNonUniformEXT
-                              Decorate 168(v) DecorationNonUniformEXT
-                              Decorate 171 DecorationNonUniformEXT
+                              Decorate 163 DecorationNonUniformEXT
+                              Decorate 170(v) DecorationNonUniformEXT
                               Decorate 173 DecorationNonUniformEXT
-                              Decorate 178 DecorationNonUniformEXT
+                              Decorate 175 DecorationNonUniformEXT
                               Decorate 180 DecorationNonUniformEXT
-                              Decorate 184 DecorationNonUniformEXT
+                              Decorate 182 DecorationNonUniformEXT
                               Decorate 186 DecorationNonUniformEXT
                               Decorate 188 DecorationNonUniformEXT
-                              Decorate 193(m) DecorationNonUniformEXT
-                              Decorate 195 DecorationNonUniformEXT
-                              Decorate 203(s) DecorationNonUniformEXT
-                              Decorate 205 DecorationNonUniformEXT
+                              Decorate 190 DecorationNonUniformEXT
+                              Decorate 195(m) DecorationNonUniformEXT
+                              Decorate 197 DecorationNonUniformEXT
+                              Decorate 205(s) DecorationNonUniformEXT
                               Decorate 207 DecorationNonUniformEXT
+                              Decorate 209 DecorationNonUniformEXT
                2:             TypeVoid
                3:             TypeFunction 2
                6:             TypeInt 32 1
                7:             TypePointer Function 6(int)
                8:             TypeFunction 6(int) 7(ptr) 7(ptr)
-              25:      6(int) Constant 2
-              28:             TypeFloat 32
-              29:             TypePointer Function 28(float)
-              31:             TypeVector 28(float) 4
-              32:             TypePointer Input 31(fvec4)
-     33(nu_inv4):     32(ptr) Variable Input
-              34:             TypeInt 32 0
-              35:     34(int) Constant 0
-              36:             TypePointer Input 28(float)
-              42:             TypeImage 28(float) SubpassData nonsampled format:Unknown
-              43:             TypeRuntimeArray 42
-              44:             TypePointer UniformConstant 43
-45(inputAttachmentDyn):     44(ptr) Variable UniformConstant
-              48:             TypePointer UniformConstant 42
-              51:      6(int) Constant 0
-              52:             TypeVector 6(int) 2
-              53:   52(ivec2) ConstantComposite 51 51
-              58:             TypeImage 28(float) Buffer sampled format:Unknown
-              59:             TypeSampledImage 58
-              60:             TypeRuntimeArray 59
-              61:             TypePointer UniformConstant 60
-62(uniformTexelBufferDyn):     61(ptr) Variable UniformConstant
-              64:             TypePointer UniformConstant 59
-              67:      6(int) Constant 1
-              73:             TypeImage 28(float) Buffer nonsampled format:R32f
-              74:             TypeRuntimeArray 73
-              75:             TypePointer UniformConstant 74
-76(storageTexelBufferDyn):     75(ptr) Variable UniformConstant
-              78:             TypePointer UniformConstant 73
-       85(uname):             TypeStruct 28(float)
-              86:             TypeRuntimeArray 85(uname)
-              87:             TypePointer Uniform 86
-88(uniformBuffer):     87(ptr) Variable Uniform
-              89:             TypePointer Input 6(int)
-       90(nu_ii):     89(ptr) Variable Input
-              92:             TypePointer Uniform 28(float)
-       97(bname):             TypeStruct 28(float)
-              98:             TypeRuntimeArray 97(bname)
-              99:             TypePointer Uniform 98
-100(storageBuffer):     99(ptr) Variable Uniform
-             106:             TypeImage 28(float) 2D sampled format:Unknown
-             107:             TypeSampledImage 106
-             108:             TypeRuntimeArray 107
-             109:             TypePointer UniformConstant 108
-110(sampledImage):    109(ptr) Variable UniformConstant
-             112:             TypePointer UniformConstant 107
-             115:             TypeVector 28(float) 2
-             116:   28(float) Constant 1056964608
-             117:  115(fvec2) ConstantComposite 116 116
-             122:             TypeImage 28(float) 2D nonsampled format:R32f
-             123:             TypeRuntimeArray 122
-             124:             TypePointer UniformConstant 123
-125(storageImage):    124(ptr) Variable UniformConstant
-             127:             TypePointer UniformConstant 122
-             130:   52(ivec2) ConstantComposite 67 67
-             135:             TypeRuntimeArray 42
-             136:             TypePointer UniformConstant 135
-137(inputAttachment):    136(ptr) Variable UniformConstant
-             145:             TypeRuntimeArray 59
-             146:             TypePointer UniformConstant 145
-147(uniformTexelBuffer):    146(ptr) Variable UniformConstant
-             156:             TypeRuntimeArray 73
-             157:             TypePointer UniformConstant 156
-158(storageTexelBuffer):    157(ptr) Variable UniformConstant
-             166:             TypeVector 6(int) 4
-             167:             TypePointer Function 166(ivec4)
-             169:     34(int) Constant 1
-             176:     34(int) Constant 2
-             191:             TypeMatrix 31(fvec4) 4
-             192:             TypePointer Function 191
-          201(S):             TypeStruct 6(int)
-             202:             TypePointer Function 201(S)
+              26:      6(int) Constant 2
+              30:             TypeFloat 32
+              31:             TypePointer Function 30(float)
+              33:             TypeVector 30(float) 4
+              34:             TypePointer Input 33(fvec4)
+     35(nu_inv4):     34(ptr) Variable Input
+              36:             TypeInt 32 0
+              37:     36(int) Constant 0
+              38:             TypePointer Input 30(float)
+              44:             TypeImage 30(float) SubpassData nonsampled format:Unknown
+              45:             TypeRuntimeArray 44
+              46:             TypePointer UniformConstant 45
+47(inputAttachmentDyn):     46(ptr) Variable UniformConstant
+              50:             TypePointer UniformConstant 44
+              53:      6(int) Constant 0
+              54:             TypeVector 6(int) 2
+              55:   54(ivec2) ConstantComposite 53 53
+              60:             TypeImage 30(float) Buffer sampled format:Unknown
+              61:             TypeSampledImage 60
+              62:             TypeRuntimeArray 61
+              63:             TypePointer UniformConstant 62
+64(uniformTexelBufferDyn):     63(ptr) Variable UniformConstant
+              66:             TypePointer UniformConstant 61
+              69:      6(int) Constant 1
+              75:             TypeImage 30(float) Buffer nonsampled format:R32f
+              76:             TypeRuntimeArray 75
+              77:             TypePointer UniformConstant 76
+78(storageTexelBufferDyn):     77(ptr) Variable UniformConstant
+              80:             TypePointer UniformConstant 75
+       87(uname):             TypeStruct 30(float)
+              88:             TypeRuntimeArray 87(uname)
+              89:             TypePointer Uniform 88
+90(uniformBuffer):     89(ptr) Variable Uniform
+              91:             TypePointer Input 6(int)
+       92(nu_ii):     91(ptr) Variable Input
+              94:             TypePointer Uniform 30(float)
+       99(bname):             TypeStruct 30(float)
+             100:             TypeRuntimeArray 99(bname)
+             101:             TypePointer Uniform 100
+102(storageBuffer):    101(ptr) Variable Uniform
+             108:             TypeImage 30(float) 2D sampled format:Unknown
+             109:             TypeSampledImage 108
+             110:             TypeRuntimeArray 109
+             111:             TypePointer UniformConstant 110
+112(sampledImage):    111(ptr) Variable UniformConstant
+             114:             TypePointer UniformConstant 109
+             117:             TypeVector 30(float) 2
+             118:   30(float) Constant 1056964608
+             119:  117(fvec2) ConstantComposite 118 118
+             124:             TypeImage 30(float) 2D nonsampled format:R32f
+             125:             TypeRuntimeArray 124
+             126:             TypePointer UniformConstant 125
+127(storageImage):    126(ptr) Variable UniformConstant
+             129:             TypePointer UniformConstant 124
+             132:   54(ivec2) ConstantComposite 69 69
+             137:             TypeRuntimeArray 44
+             138:             TypePointer UniformConstant 137
+139(inputAttachment):    138(ptr) Variable UniformConstant
+             147:             TypeRuntimeArray 61
+             148:             TypePointer UniformConstant 147
+149(uniformTexelBuffer):    148(ptr) Variable UniformConstant
+             158:             TypeRuntimeArray 75
+             159:             TypePointer UniformConstant 158
+160(storageTexelBuffer):    159(ptr) Variable UniformConstant
+             168:             TypeVector 6(int) 4
+             169:             TypePointer Function 168(ivec4)
+             171:     36(int) Constant 1
+             178:     36(int) Constant 2
+             193:             TypeMatrix 33(fvec4) 4
+             194:             TypePointer Function 193
+          203(S):             TypeStruct 6(int)
+             204:             TypePointer Function 203(S)
          4(main):           2 Function None 3
                5:             Label
            16(a):      7(ptr) Variable Function
        17(nu_li):      7(ptr) Variable Function
        18(param):      7(ptr) Variable Function
        20(param):      7(ptr) Variable Function
-           30(b):     29(ptr) Variable Function
-       39(nu_gf):     29(ptr) Variable Function
-       46(dyn_i):      7(ptr) Variable Function
-          168(v):    167(ptr) Variable Function
-         183(uv):    167(ptr) Variable Function
-          193(m):    192(ptr) Variable Function
-          203(s):    202(ptr) Variable Function
+           32(b):     31(ptr) Variable Function
+       41(nu_gf):     31(ptr) Variable Function
+       48(dyn_i):      7(ptr) Variable Function
+          170(v):    169(ptr) Variable Function
+         185(uv):    169(ptr) Variable Function
+          195(m):    194(ptr) Variable Function
+          205(s):    204(ptr) Variable Function
               19:      6(int) Load 17(nu_li)
                               Store 18(param) 19
               21:      6(int) FunctionCall 11(foo(i1;i1;) 18(param) 20(param)
@@ -224,130 +224,132 @@
                               Store 17(nu_li) 22
                               Store 16(a) 21
               23:      6(int) Load 16(a)
-              24:      6(int) Load 16(a)
-              26:      6(int) IMul 24 25
-              27:      6(int) IAdd 23 26
-                              Store 17(nu_li) 27
-              37:     36(ptr) AccessChain 33(nu_inv4) 35
-              38:   28(float) Load 37
-              40:   28(float) Load 39(nu_gf)
-              41:   28(float) FMul 38 40
-                              Store 30(b) 41
-              47:      6(int) Load 46(dyn_i)
-              49:     48(ptr) AccessChain 45(inputAttachmentDyn) 47
-              50:          42 Load 49
-              54:   31(fvec4) ImageRead 50 53
-              55:   28(float) CompositeExtract 54 0
-              56:   28(float) Load 30(b)
-              57:   28(float) FAdd 56 55
-                              Store 30(b) 57
-              63:      6(int) Load 46(dyn_i)
-              65:     64(ptr) AccessChain 62(uniformTexelBufferDyn) 63
-              66:          59 Load 65
-              68:          58 Image 66
-              69:   31(fvec4) ImageFetch 68 67
-              70:   28(float) CompositeExtract 69 0
-              71:   28(float) Load 30(b)
-              72:   28(float) FAdd 71 70
-                              Store 30(b) 72
-              77:      6(int) Load 46(dyn_i)
-              79:     78(ptr) AccessChain 76(storageTexelBufferDyn) 77
-              80:          73 Load 79
-              81:   31(fvec4) ImageRead 80 67
-              82:   28(float) CompositeExtract 81 0
-              83:   28(float) Load 30(b)
-              84:   28(float) FAdd 83 82
-                              Store 30(b) 84
-              91:      6(int) Load 90(nu_ii)
-              93:     92(ptr) AccessChain 88(uniformBuffer) 91 51
-              94:   28(float) Load 93
-              95:   28(float) Load 30(b)
-              96:   28(float) FAdd 95 94
-                              Store 30(b) 96
-             101:      6(int) Load 90(nu_ii)
-             102:     92(ptr) AccessChain 100(storageBuffer) 101 51
-             103:   28(float) Load 102
-             104:   28(float) Load 30(b)
-             105:   28(float) FAdd 104 103
-                              Store 30(b) 105
-             111:      6(int) Load 90(nu_ii)
-             113:    112(ptr) AccessChain 110(sampledImage) 111
-             114:         107 Load 113
-             118:   31(fvec4) ImageSampleImplicitLod 114 117
-             119:   28(float) CompositeExtract 118 0
-             120:   28(float) Load 30(b)
-             121:   28(float) FAdd 120 119
-                              Store 30(b) 121
-             126:      6(int) Load 90(nu_ii)
-             128:    127(ptr) AccessChain 125(storageImage) 126
-             129:         122 Load 128
-             131:   31(fvec4) ImageRead 129 130
-             132:   28(float) CompositeExtract 131 0
-             133:   28(float) Load 30(b)
-             134:   28(float) FAdd 133 132
-                              Store 30(b) 134
-             138:      6(int) Load 90(nu_ii)
-             139:     48(ptr) AccessChain 137(inputAttachment) 138
-             140:          42 Load 139
-             141:   31(fvec4) ImageRead 140 53
-             142:   28(float) CompositeExtract 141 0
-             143:   28(float) Load 30(b)
-             144:   28(float) FAdd 143 142
-                              Store 30(b) 144
-             148:      6(int) Load 90(nu_ii)
-             149:     64(ptr) AccessChain 147(uniformTexelBuffer) 148
-             150:          59 Load 149
-             151:          58 Image 150
-             152:   31(fvec4) ImageFetch 151 67
-             153:   28(float) CompositeExtract 152 0
-             154:   28(float) Load 30(b)
-             155:   28(float) FAdd 154 153
-                              Store 30(b) 155
-             159:      6(int) Load 90(nu_ii)
-             160:     78(ptr) AccessChain 158(storageTexelBuffer) 159
-             161:          73 Load 160
-             162:   31(fvec4) ImageRead 161 67
-             163:   28(float) CompositeExtract 162 0
-             164:   28(float) Load 30(b)
-             165:   28(float) FAdd 164 163
-                              Store 30(b) 165
-             170:      7(ptr) AccessChain 168(v) 169
-             171:      6(int) Load 170
-             172:     92(ptr) AccessChain 88(uniformBuffer) 171 51
-             173:   28(float) Load 172
-             174:   28(float) Load 30(b)
-             175:   28(float) FAdd 174 173
-                              Store 30(b) 175
-             177:      7(ptr) AccessChain 168(v) 176
-             178:      6(int) Load 177
-             179:     92(ptr) AccessChain 88(uniformBuffer) 178 51
-             180:   28(float) Load 179
-             181:   28(float) Load 30(b)
-             182:   28(float) FAdd 181 180
-                              Store 30(b) 182
-             184:      6(int) Load 90(nu_ii)
-             185:      7(ptr) AccessChain 183(uv) 184
-             186:      6(int) Load 185
-             187:     92(ptr) AccessChain 88(uniformBuffer) 186 51
-             188:   28(float) Load 187
-             189:   28(float) Load 30(b)
-             190:   28(float) FAdd 189 188
-                              Store 30(b) 190
-             194:     29(ptr) AccessChain 193(m) 25 176
-             195:   28(float) Load 194
-             196:      6(int) ConvertFToS 195
-             197:     92(ptr) AccessChain 88(uniformBuffer) 196 51
-             198:   28(float) Load 197
-             199:   28(float) Load 30(b)
-             200:   28(float) FAdd 199 198
-                              Store 30(b) 200
-             204:      7(ptr) AccessChain 203(s) 51
-             205:      6(int) Load 204
-             206:     92(ptr) AccessChain 88(uniformBuffer) 205 51
-             207:   28(float) Load 206
-             208:   28(float) Load 30(b)
-             209:   28(float) FAdd 208 207
-                              Store 30(b) 209
+              24:      6(int) CopyObject 23
+              25:      6(int) Load 16(a)
+              27:      6(int) IMul 25 26
+              28:      6(int) CopyObject 27
+              29:      6(int) IAdd 24 28
+                              Store 17(nu_li) 29
+              39:     38(ptr) AccessChain 35(nu_inv4) 37
+              40:   30(float) Load 39
+              42:   30(float) Load 41(nu_gf)
+              43:   30(float) FMul 40 42
+                              Store 32(b) 43
+              49:      6(int) Load 48(dyn_i)
+              51:     50(ptr) AccessChain 47(inputAttachmentDyn) 49
+              52:          44 Load 51
+              56:   33(fvec4) ImageRead 52 55
+              57:   30(float) CompositeExtract 56 0
+              58:   30(float) Load 32(b)
+              59:   30(float) FAdd 58 57
+                              Store 32(b) 59
+              65:      6(int) Load 48(dyn_i)
+              67:     66(ptr) AccessChain 64(uniformTexelBufferDyn) 65
+              68:          61 Load 67
+              70:          60 Image 68
+              71:   33(fvec4) ImageFetch 70 69
+              72:   30(float) CompositeExtract 71 0
+              73:   30(float) Load 32(b)
+              74:   30(float) FAdd 73 72
+                              Store 32(b) 74
+              79:      6(int) Load 48(dyn_i)
+              81:     80(ptr) AccessChain 78(storageTexelBufferDyn) 79
+              82:          75 Load 81
+              83:   33(fvec4) ImageRead 82 69
+              84:   30(float) CompositeExtract 83 0
+              85:   30(float) Load 32(b)
+              86:   30(float) FAdd 85 84
+                              Store 32(b) 86
+              93:      6(int) Load 92(nu_ii)
+              95:     94(ptr) AccessChain 90(uniformBuffer) 93 53
+              96:   30(float) Load 95
+              97:   30(float) Load 32(b)
+              98:   30(float) FAdd 97 96
+                              Store 32(b) 98
+             103:      6(int) Load 92(nu_ii)
+             104:     94(ptr) AccessChain 102(storageBuffer) 103 53
+             105:   30(float) Load 104
+             106:   30(float) Load 32(b)
+             107:   30(float) FAdd 106 105
+                              Store 32(b) 107
+             113:      6(int) Load 92(nu_ii)
+             115:    114(ptr) AccessChain 112(sampledImage) 113
+             116:         109 Load 115
+             120:   33(fvec4) ImageSampleImplicitLod 116 119
+             121:   30(float) CompositeExtract 120 0
+             122:   30(float) Load 32(b)
+             123:   30(float) FAdd 122 121
+                              Store 32(b) 123
+             128:      6(int) Load 92(nu_ii)
+             130:    129(ptr) AccessChain 127(storageImage) 128
+             131:         124 Load 130
+             133:   33(fvec4) ImageRead 131 132
+             134:   30(float) CompositeExtract 133 0
+             135:   30(float) Load 32(b)
+             136:   30(float) FAdd 135 134
+                              Store 32(b) 136
+             140:      6(int) Load 92(nu_ii)
+             141:     50(ptr) AccessChain 139(inputAttachment) 140
+             142:          44 Load 141
+             143:   33(fvec4) ImageRead 142 55
+             144:   30(float) CompositeExtract 143 0
+             145:   30(float) Load 32(b)
+             146:   30(float) FAdd 145 144
+                              Store 32(b) 146
+             150:      6(int) Load 92(nu_ii)
+             151:     66(ptr) AccessChain 149(uniformTexelBuffer) 150
+             152:          61 Load 151
+             153:          60 Image 152
+             154:   33(fvec4) ImageFetch 153 69
+             155:   30(float) CompositeExtract 154 0
+             156:   30(float) Load 32(b)
+             157:   30(float) FAdd 156 155
+                              Store 32(b) 157
+             161:      6(int) Load 92(nu_ii)
+             162:     80(ptr) AccessChain 160(storageTexelBuffer) 161
+             163:          75 Load 162
+             164:   33(fvec4) ImageRead 163 69
+             165:   30(float) CompositeExtract 164 0
+             166:   30(float) Load 32(b)
+             167:   30(float) FAdd 166 165
+                              Store 32(b) 167
+             172:      7(ptr) AccessChain 170(v) 171
+             173:      6(int) Load 172
+             174:     94(ptr) AccessChain 90(uniformBuffer) 173 53
+             175:   30(float) Load 174
+             176:   30(float) Load 32(b)
+             177:   30(float) FAdd 176 175
+                              Store 32(b) 177
+             179:      7(ptr) AccessChain 170(v) 178
+             180:      6(int) Load 179
+             181:     94(ptr) AccessChain 90(uniformBuffer) 180 53
+             182:   30(float) Load 181
+             183:   30(float) Load 32(b)
+             184:   30(float) FAdd 183 182
+                              Store 32(b) 184
+             186:      6(int) Load 92(nu_ii)
+             187:      7(ptr) AccessChain 185(uv) 186
+             188:      6(int) Load 187
+             189:     94(ptr) AccessChain 90(uniformBuffer) 188 53
+             190:   30(float) Load 189
+             191:   30(float) Load 32(b)
+             192:   30(float) FAdd 191 190
+                              Store 32(b) 192
+             196:     31(ptr) AccessChain 195(m) 26 178
+             197:   30(float) Load 196
+             198:      6(int) ConvertFToS 197
+             199:     94(ptr) AccessChain 90(uniformBuffer) 198 53
+             200:   30(float) Load 199
+             201:   30(float) Load 32(b)
+             202:   30(float) FAdd 201 200
+                              Store 32(b) 202
+             206:      7(ptr) AccessChain 205(s) 53
+             207:      6(int) Load 206
+             208:     94(ptr) AccessChain 90(uniformBuffer) 207 53
+             209:   30(float) Load 208
+             210:   30(float) Load 32(b)
+             211:   30(float) FAdd 210 209
+                              Store 32(b) 211
                               Return
                               FunctionEnd
   11(foo(i1;i1;):      6(int) Function None 8
diff --git a/Test/baseResults/spv.nonuniform2.frag.out b/Test/baseResults/spv.nonuniform2.frag.out
new file mode 100644
index 0000000..38cdf35
--- /dev/null
+++ b/Test/baseResults/spv.nonuniform2.frag.out
@@ -0,0 +1,53 @@
+spv.nonuniform2.frag
+// Module Version 10000
+// Generated by (magic number): 80007
+// Id's are bound by 24
+
+                              Capability Shader
+                              Capability ImageBuffer
+                              Capability CapabilityShaderNonUniformEXT
+                              Capability CapabilityRuntimeDescriptorArrayEXT
+                              Capability CapabilityStorageTexelBufferArrayNonUniformIndexingEXT
+                              Extension  "SPV_EXT_descriptor_indexing"
+               1:             ExtInstImport  "GLSL.std.450"
+                              MemoryModel Logical GLSL450
+                              EntryPoint Fragment 4  "main" 9 16
+                              ExecutionMode 4 OriginUpperLeft
+                              Source GLSL 450
+                              SourceExtension  "GL_EXT_nonuniform_qualifier"
+                              Name 4  "main"
+                              Name 9  "FragColor"
+                              Name 13  "data"
+                              Name 16  "rIndex"
+                              Decorate 9(FragColor) Location 0
+                              Decorate 13(data) DescriptorSet 0
+                              Decorate 13(data) Binding 4
+                              Decorate 16(rIndex) Flat
+                              Decorate 16(rIndex) Location 3
+                              Decorate 18 DecorationNonUniformEXT
+                              Decorate 21 DecorationNonUniformEXT
+               2:             TypeVoid
+               3:             TypeFunction 2
+               6:             TypeFloat 32
+               7:             TypeVector 6(float) 4
+               8:             TypePointer Output 7(fvec4)
+    9(FragColor):      8(ptr) Variable Output
+              10:             TypeImage 6(float) Buffer nonsampled format:Rgba32f
+              11:             TypeRuntimeArray 10
+              12:             TypePointer UniformConstant 11
+        13(data):     12(ptr) Variable UniformConstant
+              14:             TypeInt 32 1
+              15:             TypePointer Input 14(int)
+      16(rIndex):     15(ptr) Variable Input
+              19:             TypePointer UniformConstant 10
+              22:     14(int) Constant 0
+         4(main):           2 Function None 3
+               5:             Label
+              17:     14(int) Load 16(rIndex)
+              18:     14(int) CopyObject 17
+              20:     19(ptr) AccessChain 13(data) 18
+              21:          10 Load 20
+              23:    7(fvec4) ImageRead 21 22
+                              Store 9(FragColor) 23
+                              Return
+                              FunctionEnd
diff --git a/Test/spv.nonuniform2.frag b/Test/spv.nonuniform2.frag
new file mode 100644
index 0000000..9bb7eaa
--- /dev/null
+++ b/Test/spv.nonuniform2.frag
@@ -0,0 +1,9 @@
+#version 450

+#extension GL_EXT_nonuniform_qualifier : require

+layout(set=0,binding=4,rgba32f) uniform imageBuffer data[];

+layout(location = 0) out vec4     FragColor;

+layout(location = 3) in flat int  rIndex;

+void main()

+{

+  FragColor = imageLoad(data[nonuniformEXT(rIndex)], 0);

+}

diff --git a/glslang/Include/intermediate.h b/glslang/Include/intermediate.h
index 32e684c..a204904 100644
--- a/glslang/Include/intermediate.h
+++ b/glslang/Include/intermediate.h
@@ -85,6 +85,8 @@
     EOpPreIncrement,
     EOpPreDecrement,
 
+    EOpCopyObject,
+
     // (u)int* -> bool
     EOpConvInt8ToBool,
     EOpConvUint8ToBool,
diff --git a/glslang/MachineIndependent/ParseHelper.cpp b/glslang/MachineIndependent/ParseHelper.cpp
index 1aa466c..6a8d379 100644
--- a/glslang/MachineIndependent/ParseHelper.cpp
+++ b/glslang/MachineIndependent/ParseHelper.cpp
@@ -6951,9 +6951,10 @@
         break;
 
     case EOpConstructNonuniform:
-        node->getWritableType().getQualifier().nonUniform = true;
-        return node;
-        break;
+        // Make a nonuniform copy of node
+        newNode = intermediate.addBuiltInFunctionCall(node->getLoc(), EOpCopyObject, true, node, node->getType());
+        newNode->getWritableType().getQualifier().nonUniform = true;
+        return newNode;
 
     case EOpConstructReference:
         // construct reference from reference
diff --git a/glslang/MachineIndependent/intermOut.cpp b/glslang/MachineIndependent/intermOut.cpp
index a2c3627..5e2eed1 100644
--- a/glslang/MachineIndependent/intermOut.cpp
+++ b/glslang/MachineIndependent/intermOut.cpp
@@ -237,6 +237,7 @@
     case EOpPostDecrement:  out.debug << "Post-Decrement";       break;
     case EOpPreIncrement:   out.debug << "Pre-Increment";        break;
     case EOpPreDecrement:   out.debug << "Pre-Decrement";        break;
+    case EOpCopyObject:     out.debug << "copy object";          break;
 
     // * -> bool
     case EOpConvInt8ToBool:    out.debug << "Convert int8_t to bool";  break;
diff --git a/gtests/Spv.FromFile.cpp b/gtests/Spv.FromFile.cpp
index a1797fd..009fc7b 100644
--- a/gtests/Spv.FromFile.cpp
+++ b/gtests/Spv.FromFile.cpp
@@ -335,6 +335,7 @@
         "spv.noDeadDecorations.vert",
         "spv.nonSquare.vert",
         "spv.nonuniform.frag",
+        "spv.nonuniform2.frag",
         "spv.noWorkgroup.comp",
         "spv.offsets.frag",
         "spv.Operations.frag",