radeon/llvm: Fix isEG tablegen predicate
[mesa.git] / src / gallium / drivers / radeon / radeon_setup_tgsi_llvm.c
index 502d551dce1481a01bf0a6e06884b39eb0bcfeef..04469e28759f02d9bf286214e145fa21e736d5fa 100644 (file)
 #include "tgsi/tgsi_info.h"
 #include "tgsi/tgsi_parse.h"
 #include "util/u_math.h"
+#include "util/u_memory.h"
 #include "util/u_debug.h"
 
+#include <llvm-c/Core.h>
 #include <llvm-c/Transforms/Scalar.h>
 
 static struct radeon_llvm_loop * get_current_loop(struct radeon_llvm_context * ctx)
@@ -55,19 +57,6 @@ unsigned radeon_llvm_reg_index_soa(unsigned index, unsigned chan)
  return (index * 4) + chan;
 }
 
-static void radeon_llvm_fetch_args_2_reverse_soa(
-       struct lp_build_tgsi_context * bld_base,
-       struct lp_build_emit_data * emit_data)
-{
-       assert(emit_data->info->num_src == 2);
-       emit_data->args[0] = lp_build_emit_fetch(bld_base, emit_data->inst,
-                                                       1, emit_data->chan);
-       emit_data->args[1] = lp_build_emit_fetch(bld_base, emit_data->inst,
-                                                       0, emit_data->chan);
-       emit_data->arg_count = 2;
-       emit_data->dst_type = LLVMTypeOf(emit_data->args[0]);
-}
-
 static LLVMValueRef emit_swizzle(
        struct lp_build_tgsi_context * bld_base,
         LLVMValueRef value,
@@ -76,14 +65,19 @@ static LLVMValueRef emit_swizzle(
        unsigned swizzle_z,
        unsigned swizzle_w)
 {
-       unsigned char swizzles[4];
-       swizzles[0] = swizzle_x;
-       swizzles[1] = swizzle_y;
-       swizzles[2] = swizzle_z;
-       swizzles[3] = swizzle_w;
-
-
-       return lp_build_swizzle_aos(&bld_base->base, value, swizzles);
+       LLVMValueRef swizzles[4];
+       LLVMTypeRef i32t =
+               LLVMInt32TypeInContext(bld_base->base.gallivm->context);
+
+       swizzles[0] = LLVMConstInt(i32t, swizzle_x, 0);
+       swizzles[1] = LLVMConstInt(i32t, swizzle_y, 0);
+       swizzles[2] = LLVMConstInt(i32t, swizzle_z, 0);
+       swizzles[3] = LLVMConstInt(i32t, swizzle_w, 0);
+
+       return LLVMBuildShuffleVector(bld_base->base.gallivm->builder,
+               value,
+               LLVMGetUndef(LLVMTypeOf(value)),
+               LLVMConstVector(swizzles, 4), "");
 }
 
 static LLVMValueRef
@@ -165,11 +159,21 @@ emit_fetch_temporary(
 {
        struct lp_build_tgsi_soa_context *bld = lp_soa_context(bld_base);
        LLVMBuilderRef builder = bld_base->base.gallivm->builder;
+       if (swizzle == ~0) {
+               LLVMValueRef values[TGSI_NUM_CHANNELS] = {};
+               unsigned chan;
+               for (chan = 0; chan < TGSI_NUM_CHANNELS; chan++) {
+                       values[chan] = emit_fetch_temporary(bld_base, reg, type, chan);
+               }
+               return lp_build_gather_values(bld_base->base.gallivm, values,
+                                               TGSI_NUM_CHANNELS);
+       }
+
        if (reg->Register.Indirect) {
                LLVMValueRef array_index = emit_array_index(bld, reg, swizzle);
                LLVMValueRef ptr = LLVMBuildGEP(builder, bld->temps_array, &array_index,
                                                1, "");
-       return LLVMBuildLoad(builder, ptr, "");
+               return LLVMBuildLoad(builder, ptr, "");
        } else {
                LLVMValueRef temp_ptr;
                temp_ptr = lp_get_temp_ptr_soa(bld, reg->Register.Index, swizzle);
@@ -509,6 +513,107 @@ static void kil_emit(
        }
 }
 
+
+static void emit_prepare_cube_coords(
+               struct lp_build_tgsi_context * bld_base,
+               struct lp_build_emit_data * emit_data)
+{
+       boolean shadowcube = (emit_data->inst->Texture.Texture == TGSI_TEXTURE_SHADOWCUBE);
+       struct gallivm_state * gallivm = bld_base->base.gallivm;
+       LLVMBuilderRef builder = gallivm->builder;
+       LLVMTypeRef type = bld_base->base.elem_type;
+       LLVMValueRef coords[4];
+       LLVMValueRef mad_args[3];
+       unsigned i, cnt;
+
+       LLVMValueRef v = build_intrinsic(builder, "llvm.AMDGPU.cube",
+                       LLVMVectorType(type, 4),
+                       &emit_data->args[0],1, LLVMReadNoneAttribute);
+
+       /* save src.w for shadow cube */
+       cnt = shadowcube ? 3 : 4;
+
+       for (i = 0; i < cnt; ++i) {
+               LLVMValueRef idx = lp_build_const_int32(gallivm, i);
+               coords[i] = LLVMBuildExtractElement(builder, v, idx, "");
+       }
+
+       coords[2] = build_intrinsic(builder, "llvm.AMDIL.fabs.",
+                       type, &coords[2], 1, LLVMReadNoneAttribute);
+       coords[2] = build_intrinsic(builder, "llvm.AMDGPU.rcp",
+                       type, &coords[2], 1, LLVMReadNoneAttribute);
+
+       mad_args[1] = coords[2];
+       mad_args[2] = LLVMConstReal(type, 1.5);
+
+       mad_args[0] = coords[0];
+       coords[0] = build_intrinsic(builder, "llvm.AMDIL.mad.",
+                       type, mad_args, 3, LLVMReadNoneAttribute);
+
+       mad_args[0] = coords[1];
+       coords[1] = build_intrinsic(builder, "llvm.AMDIL.mad.",
+                       type, mad_args, 3, LLVMReadNoneAttribute);
+
+       /* apply yxwy swizzle to cooords */
+       coords[2] = coords[3];
+       coords[3] = coords[1];
+       coords[1] = coords[0];
+       coords[0] = coords[3];
+
+       emit_data->args[0] = lp_build_gather_values(bld_base->base.gallivm,
+                                               coords, 4);
+}
+
+static void txd_fetch_args(
+       struct lp_build_tgsi_context * bld_base,
+       struct lp_build_emit_data * emit_data)
+{
+       const struct tgsi_full_instruction * inst = emit_data->inst;
+
+       LLVMValueRef coords[4];
+       unsigned chan, src;
+       for (src = 0; src < 3; src++) {
+               for (chan = 0; chan < 4; chan++)
+                       coords[chan] = lp_build_emit_fetch(bld_base, inst, src, chan);
+
+               emit_data->args[src] = lp_build_gather_values(bld_base->base.gallivm,
+                               coords, 4);
+       }
+       emit_data->arg_count = 3;
+       emit_data->dst_type = LLVMVectorType(bld_base->base.elem_type, 4);
+}
+
+
+static void txp_fetch_args(
+       struct lp_build_tgsi_context * bld_base,
+       struct lp_build_emit_data * emit_data)
+{
+       const struct tgsi_full_instruction * inst = emit_data->inst;
+       LLVMValueRef src_w;
+       unsigned chan;
+       LLVMValueRef coords[4];
+
+       emit_data->dst_type = LLVMVectorType(bld_base->base.elem_type, 4);
+       src_w = lp_build_emit_fetch(bld_base, emit_data->inst, 0, TGSI_CHAN_W);
+
+       for (chan = 0; chan < 3; chan++ ) {
+               LLVMValueRef arg = lp_build_emit_fetch(bld_base,
+                                               emit_data->inst, 0, chan);
+               coords[chan] = lp_build_emit_llvm_binary(bld_base,
+                                       TGSI_OPCODE_DIV, arg, src_w);
+       }
+       coords[3] = bld_base->base.one;
+       emit_data->args[0] = lp_build_gather_values(bld_base->base.gallivm,
+                                               coords, 4);
+       emit_data->arg_count = 1;
+
+       if ((inst->Texture.Texture == TGSI_TEXTURE_CUBE ||
+            inst->Texture.Texture == TGSI_TEXTURE_SHADOWCUBE) &&
+           inst->Instruction.Opcode != TGSI_OPCODE_TXQ) {
+               emit_prepare_cube_coords(bld_base, emit_data);
+       }
+}
+
 static void tex_fetch_args(
        struct lp_build_tgsi_context * bld_base,
        struct lp_build_emit_data * emit_data)
@@ -521,16 +626,58 @@ static void tex_fetch_args(
 
        */
 
+       const struct tgsi_full_instruction * inst = emit_data->inst;
+
        LLVMValueRef coords[4];
        unsigned chan;
        for (chan = 0; chan < 4; chan++) {
-               coords[chan] = lp_build_emit_fetch(bld_base, emit_data->inst, 0, chan);
+               coords[chan] = lp_build_emit_fetch(bld_base, inst, 0, chan);
        }
 
        emit_data->arg_count = 1;
        emit_data->args[0] = lp_build_gather_values(bld_base->base.gallivm,
                                                coords, 4);
        emit_data->dst_type = LLVMVectorType(bld_base->base.elem_type, 4);
+
+       if ((inst->Texture.Texture == TGSI_TEXTURE_CUBE ||
+            inst->Texture.Texture == TGSI_TEXTURE_SHADOWCUBE) &&
+           inst->Instruction.Opcode != TGSI_OPCODE_TXQ) {
+               emit_prepare_cube_coords(bld_base, emit_data);
+       }
+}
+
+static void txf_fetch_args(
+       struct lp_build_tgsi_context * bld_base,
+       struct lp_build_emit_data * emit_data)
+{
+       const struct tgsi_full_instruction * inst = emit_data->inst;
+       struct lp_build_tgsi_soa_context *bld = lp_soa_context(bld_base);
+       const struct tgsi_texture_offset * off = inst->TexOffsets;
+       LLVMTypeRef offset_type = bld_base->int_bld.elem_type;
+
+       /* fetch tex coords */
+       tex_fetch_args(bld_base, emit_data);
+
+       /* fetch tex offsets */
+       if (inst->Texture.NumOffsets) {
+               assert(inst->Texture.NumOffsets == 1);
+
+               emit_data->args[1] = LLVMConstBitCast(
+                       bld->immediates[off->Index][off->SwizzleX],
+                       offset_type);
+               emit_data->args[2] = LLVMConstBitCast(
+                       bld->immediates[off->Index][off->SwizzleY],
+                       offset_type);
+               emit_data->args[3] = LLVMConstBitCast(
+                       bld->immediates[off->Index][off->SwizzleZ],
+                       offset_type);
+       } else {
+               emit_data->args[1] = bld_base->int_bld.zero;
+               emit_data->args[2] = bld_base->int_bld.zero;
+               emit_data->args[3] = bld_base->int_bld.zero;
+       }
+
+       emit_data->arg_count = 4;
 }
 
 static void emit_icmp(
@@ -562,6 +709,37 @@ static void emit_icmp(
        emit_data->output[emit_data->chan] = v;
 }
 
+static void emit_cmp(
+               const struct lp_build_tgsi_action *action,
+               struct lp_build_tgsi_context * bld_base,
+               struct lp_build_emit_data * emit_data)
+{
+       LLVMBuilderRef builder = bld_base->base.gallivm->builder;
+       LLVMRealPredicate pred;
+       LLVMValueRef cond;
+
+       /* XXX I'm not sure whether to do unordered or ordered comparisons,
+        * but llvmpipe uses unordered comparisons, so for consistency we use
+        * unordered.  (The authors of llvmpipe aren't sure about using
+        * unordered vs ordered comparisons either.
+        */
+       switch (emit_data->inst->Instruction.Opcode) {
+       case TGSI_OPCODE_SGE: pred = LLVMRealUGE; break;
+       case TGSI_OPCODE_SEQ: pred = LLVMRealUEQ; break;
+       case TGSI_OPCODE_SLE: pred = LLVMRealULE; break;
+       case TGSI_OPCODE_SLT: pred = LLVMRealULT; break;
+       case TGSI_OPCODE_SNE: pred = LLVMRealUNE; break;
+       case TGSI_OPCODE_SGT: pred = LLVMRealUGT; break;
+       default: assert(!"unknown instruction");
+       }
+
+       cond = LLVMBuildFCmp(builder,
+               pred, emit_data->args[0], emit_data->args[1], "");
+
+       emit_data->output[emit_data->chan] = LLVMBuildSelect(builder,
+               cond, bld_base->base.one, bld_base->base.zero, "");
+}
+
 static void emit_not(
                const struct lp_build_tgsi_action * action,
                struct lp_build_tgsi_context * bld_base,
@@ -770,6 +948,51 @@ static void emit_immediate(struct lp_build_tgsi_context * bld_base,
        ctx->soa.num_immediates++;
 }
 
+LLVMValueRef
+build_intrinsic(LLVMBuilderRef builder,
+                   const char *name,
+                   LLVMTypeRef ret_type,
+                   LLVMValueRef *args,
+                   unsigned num_args,
+                   LLVMAttribute attr)
+{
+   LLVMModuleRef module = LLVMGetGlobalParent(LLVMGetBasicBlockParent(LLVMGetInsertBlock(builder)));
+   LLVMValueRef function;
+
+   function = LLVMGetNamedFunction(module, name);
+   if(!function) {
+      LLVMTypeRef arg_types[LP_MAX_FUNC_ARGS];
+      unsigned i;
+
+      assert(num_args <= LP_MAX_FUNC_ARGS);
+
+      for(i = 0; i < num_args; ++i) {
+         assert(args[i]);
+         arg_types[i] = LLVMTypeOf(args[i]);
+      }
+
+      function = lp_declare_intrinsic(module, name, ret_type, arg_types, num_args);
+
+      if (attr)
+          LLVMAddFunctionAttr(function, attr);
+   }
+
+   return LLVMBuildCall(builder, function, args, num_args, "");
+}
+
+void
+build_tgsi_intrinsic_nomem(
+ const struct lp_build_tgsi_action * action,
+ struct lp_build_tgsi_context * bld_base,
+ struct lp_build_emit_data * emit_data)
+{
+   struct lp_build_context * base = &bld_base->base;
+   emit_data->output[emit_data->chan] = build_intrinsic(
+               base->gallivm->builder, action->intr_name,
+               emit_data->dst_type, emit_data->args,
+               emit_data->arg_count, LLVMReadNoneAttribute);
+}
+
 void radeon_llvm_context_init(struct radeon_llvm_context * ctx)
 {
        struct lp_type type;
@@ -829,7 +1052,7 @@ void radeon_llvm_context_init(struct radeon_llvm_context * ctx)
 
        lp_set_default_actions(bld_base);
 
-       bld_base->op_actions[TGSI_OPCODE_IABS].emit = lp_build_tgsi_intrinsic;
+       bld_base->op_actions[TGSI_OPCODE_IABS].emit = build_tgsi_intrinsic_nomem;
        bld_base->op_actions[TGSI_OPCODE_IABS].intr_name = "llvm.AMDIL.abs.";
        bld_base->op_actions[TGSI_OPCODE_NOT].emit = emit_not;
        bld_base->op_actions[TGSI_OPCODE_AND].emit = emit_and;
@@ -860,105 +1083,98 @@ void radeon_llvm_context_init(struct radeon_llvm_context * ctx)
        bld_base->op_actions[TGSI_OPCODE_USNE].emit = emit_icmp;
        bld_base->op_actions[TGSI_OPCODE_ISGE].emit = emit_icmp;
        bld_base->op_actions[TGSI_OPCODE_ISLT].emit = emit_icmp;
-       bld_base->op_actions[TGSI_OPCODE_ROUND].emit = lp_build_tgsi_intrinsic;
+       bld_base->op_actions[TGSI_OPCODE_ROUND].emit = build_tgsi_intrinsic_nomem;
        bld_base->op_actions[TGSI_OPCODE_ROUND].intr_name = "llvm.AMDIL.round.nearest.";
-       bld_base->op_actions[TGSI_OPCODE_MIN].emit = lp_build_tgsi_intrinsic;
+       bld_base->op_actions[TGSI_OPCODE_MIN].emit = build_tgsi_intrinsic_nomem;
        bld_base->op_actions[TGSI_OPCODE_MIN].intr_name = "llvm.AMDIL.min.";
-       bld_base->op_actions[TGSI_OPCODE_MAX].emit = lp_build_tgsi_intrinsic;
+       bld_base->op_actions[TGSI_OPCODE_MAX].emit = build_tgsi_intrinsic_nomem;
        bld_base->op_actions[TGSI_OPCODE_MAX].intr_name = "llvm.AMDIL.max.";
-       bld_base->op_actions[TGSI_OPCODE_IMIN].emit = lp_build_tgsi_intrinsic;
+       bld_base->op_actions[TGSI_OPCODE_IMIN].emit = build_tgsi_intrinsic_nomem;
        bld_base->op_actions[TGSI_OPCODE_IMIN].intr_name = "llvm.AMDGPU.imin";
-       bld_base->op_actions[TGSI_OPCODE_IMAX].emit = lp_build_tgsi_intrinsic;
+       bld_base->op_actions[TGSI_OPCODE_IMAX].emit = build_tgsi_intrinsic_nomem;
        bld_base->op_actions[TGSI_OPCODE_IMAX].intr_name = "llvm.AMDGPU.imax";
-       bld_base->op_actions[TGSI_OPCODE_UMIN].emit = lp_build_tgsi_intrinsic;
+       bld_base->op_actions[TGSI_OPCODE_UMIN].emit = build_tgsi_intrinsic_nomem;
        bld_base->op_actions[TGSI_OPCODE_UMIN].intr_name = "llvm.AMDGPU.umin";
-       bld_base->op_actions[TGSI_OPCODE_UMAX].emit = lp_build_tgsi_intrinsic;
+       bld_base->op_actions[TGSI_OPCODE_UMAX].emit = build_tgsi_intrinsic_nomem;
        bld_base->op_actions[TGSI_OPCODE_UMAX].intr_name = "llvm.AMDGPU.umax";
-       bld_base->op_actions[TGSI_OPCODE_TXF].fetch_args = tex_fetch_args;
+       bld_base->op_actions[TGSI_OPCODE_TXF].fetch_args = txf_fetch_args;
        bld_base->op_actions[TGSI_OPCODE_TXF].intr_name = "llvm.AMDGPU.txf";
        bld_base->op_actions[TGSI_OPCODE_TXQ].fetch_args = tex_fetch_args;
        bld_base->op_actions[TGSI_OPCODE_TXQ].intr_name = "llvm.AMDGPU.txq";
-       bld_base->op_actions[TGSI_OPCODE_CEIL].emit = lp_build_tgsi_intrinsic;
-       bld_base->op_actions[TGSI_OPCODE_CEIL].intr_name = "llvm.AMDIL.round.neginf.";
+       bld_base->op_actions[TGSI_OPCODE_CEIL].emit = build_tgsi_intrinsic_nomem;
+       bld_base->op_actions[TGSI_OPCODE_CEIL].intr_name = "llvm.AMDIL.round.posinf.";
 
 
 
-       bld_base->op_actions[TGSI_OPCODE_ABS].emit = lp_build_tgsi_intrinsic;
+       bld_base->op_actions[TGSI_OPCODE_ABS].emit = build_tgsi_intrinsic_nomem;
        bld_base->op_actions[TGSI_OPCODE_ABS].intr_name = "llvm.AMDIL.fabs.";
-       bld_base->op_actions[TGSI_OPCODE_ARL].emit = lp_build_tgsi_intrinsic;
+       bld_base->op_actions[TGSI_OPCODE_ARL].emit = build_tgsi_intrinsic_nomem;
        bld_base->op_actions[TGSI_OPCODE_ARL].intr_name = "llvm.AMDGPU.arl";
        bld_base->op_actions[TGSI_OPCODE_BGNLOOP].emit = bgnloop_emit;
        bld_base->op_actions[TGSI_OPCODE_BRK].emit = brk_emit;
        bld_base->op_actions[TGSI_OPCODE_CONT].emit = cont_emit;
-       bld_base->op_actions[TGSI_OPCODE_CLAMP].emit = lp_build_tgsi_intrinsic;
+       bld_base->op_actions[TGSI_OPCODE_CLAMP].emit = build_tgsi_intrinsic_nomem;
        bld_base->op_actions[TGSI_OPCODE_CLAMP].intr_name = "llvm.AMDIL.clamp.";
-       bld_base->op_actions[TGSI_OPCODE_CMP].emit = lp_build_tgsi_intrinsic;
+       bld_base->op_actions[TGSI_OPCODE_CMP].emit = build_tgsi_intrinsic_nomem;
        bld_base->op_actions[TGSI_OPCODE_CMP].intr_name = "llvm.AMDGPU.cndlt";
-       bld_base->op_actions[TGSI_OPCODE_COS].emit = lp_build_tgsi_intrinsic;
+       bld_base->op_actions[TGSI_OPCODE_COS].emit = build_tgsi_intrinsic_nomem;
        bld_base->op_actions[TGSI_OPCODE_COS].intr_name = "llvm.AMDGPU.cos";
-       bld_base->op_actions[TGSI_OPCODE_DIV].emit = lp_build_tgsi_intrinsic;
+       bld_base->op_actions[TGSI_OPCODE_DIV].emit = build_tgsi_intrinsic_nomem;
        bld_base->op_actions[TGSI_OPCODE_DIV].intr_name = "llvm.AMDGPU.div";
        bld_base->op_actions[TGSI_OPCODE_ELSE].emit = else_emit;
        bld_base->op_actions[TGSI_OPCODE_ENDIF].emit = endif_emit;
        bld_base->op_actions[TGSI_OPCODE_ENDLOOP].emit = endloop_emit;
-       bld_base->op_actions[TGSI_OPCODE_EX2].emit = lp_build_tgsi_intrinsic;
+       bld_base->op_actions[TGSI_OPCODE_EX2].emit = build_tgsi_intrinsic_nomem;
        bld_base->op_actions[TGSI_OPCODE_EX2].intr_name = "llvm.AMDIL.exp.";
-       bld_base->op_actions[TGSI_OPCODE_FLR].emit = lp_build_tgsi_intrinsic;
+       bld_base->op_actions[TGSI_OPCODE_FLR].emit = build_tgsi_intrinsic_nomem;
        bld_base->op_actions[TGSI_OPCODE_FLR].intr_name = "llvm.AMDGPU.floor";
-       bld_base->op_actions[TGSI_OPCODE_FRC].emit = lp_build_tgsi_intrinsic;
+       bld_base->op_actions[TGSI_OPCODE_FRC].emit = build_tgsi_intrinsic_nomem;
        bld_base->op_actions[TGSI_OPCODE_FRC].intr_name = "llvm.AMDIL.fraction.";
        bld_base->op_actions[TGSI_OPCODE_IF].emit = if_emit;
        bld_base->op_actions[TGSI_OPCODE_KIL].emit = kil_emit;
        bld_base->op_actions[TGSI_OPCODE_KIL].intr_name = "llvm.AMDGPU.kill";
        bld_base->op_actions[TGSI_OPCODE_KILP].emit = lp_build_tgsi_intrinsic;
        bld_base->op_actions[TGSI_OPCODE_KILP].intr_name = "llvm.AMDGPU.kilp";
-       bld_base->op_actions[TGSI_OPCODE_LG2].emit = lp_build_tgsi_intrinsic;
+       bld_base->op_actions[TGSI_OPCODE_LG2].emit = build_tgsi_intrinsic_nomem;
        bld_base->op_actions[TGSI_OPCODE_LG2].intr_name = "llvm.AMDIL.log.";
-       bld_base->op_actions[TGSI_OPCODE_LRP].emit = lp_build_tgsi_intrinsic;
+       bld_base->op_actions[TGSI_OPCODE_LRP].emit = build_tgsi_intrinsic_nomem;
        bld_base->op_actions[TGSI_OPCODE_LRP].intr_name = "llvm.AMDGPU.lrp";
-       bld_base->op_actions[TGSI_OPCODE_MIN].emit = lp_build_tgsi_intrinsic;
+       bld_base->op_actions[TGSI_OPCODE_MIN].emit = build_tgsi_intrinsic_nomem;
        bld_base->op_actions[TGSI_OPCODE_MIN].intr_name = "llvm.AMDIL.min.";
-       bld_base->op_actions[TGSI_OPCODE_MAD].emit = lp_build_tgsi_intrinsic;
+       bld_base->op_actions[TGSI_OPCODE_MAD].emit = build_tgsi_intrinsic_nomem;
        bld_base->op_actions[TGSI_OPCODE_MAD].intr_name = "llvm.AMDIL.mad.";
-       bld_base->op_actions[TGSI_OPCODE_MAX].emit = lp_build_tgsi_intrinsic;
+       bld_base->op_actions[TGSI_OPCODE_MAX].emit = build_tgsi_intrinsic_nomem;
        bld_base->op_actions[TGSI_OPCODE_MAX].intr_name = "llvm.AMDIL.max.";
-       bld_base->op_actions[TGSI_OPCODE_MUL].emit = lp_build_tgsi_intrinsic;
+       bld_base->op_actions[TGSI_OPCODE_MUL].emit = build_tgsi_intrinsic_nomem;
        bld_base->op_actions[TGSI_OPCODE_MUL].intr_name = "llvm.AMDGPU.mul";
-       bld_base->op_actions[TGSI_OPCODE_POW].emit = lp_build_tgsi_intrinsic;
+       bld_base->op_actions[TGSI_OPCODE_POW].emit = build_tgsi_intrinsic_nomem;
        bld_base->op_actions[TGSI_OPCODE_POW].intr_name = "llvm.AMDGPU.pow";
-       bld_base->op_actions[TGSI_OPCODE_RCP].emit = lp_build_tgsi_intrinsic;
+       bld_base->op_actions[TGSI_OPCODE_RCP].emit = build_tgsi_intrinsic_nomem;
        bld_base->op_actions[TGSI_OPCODE_RCP].intr_name = "llvm.AMDGPU.rcp";
-       bld_base->op_actions[TGSI_OPCODE_SSG].emit = lp_build_tgsi_intrinsic;
+       bld_base->op_actions[TGSI_OPCODE_SSG].emit = build_tgsi_intrinsic_nomem;
        bld_base->op_actions[TGSI_OPCODE_SSG].intr_name = "llvm.AMDGPU.ssg";
-       bld_base->op_actions[TGSI_OPCODE_SGE].emit = lp_build_tgsi_intrinsic;
-       bld_base->op_actions[TGSI_OPCODE_SGE].intr_name = "llvm.AMDGPU.sge";
-       bld_base->op_actions[TGSI_OPCODE_SEQ].emit = lp_build_tgsi_intrinsic;
-       bld_base->op_actions[TGSI_OPCODE_SEQ].intr_name = "llvm.AMDGPU.seq";
-       bld_base->op_actions[TGSI_OPCODE_SLE].fetch_args = radeon_llvm_fetch_args_2_reverse_soa;
-       bld_base->op_actions[TGSI_OPCODE_SLE].emit = lp_build_tgsi_intrinsic;
-       bld_base->op_actions[TGSI_OPCODE_SLE].intr_name = "llvm.AMDGPU.sge";
-       bld_base->op_actions[TGSI_OPCODE_SLT].fetch_args = radeon_llvm_fetch_args_2_reverse_soa;
-       bld_base->op_actions[TGSI_OPCODE_SLT].emit = lp_build_tgsi_intrinsic;
-       bld_base->op_actions[TGSI_OPCODE_SLT].intr_name = "llvm.AMDGPU.sgt";
-       bld_base->op_actions[TGSI_OPCODE_SNE].emit = lp_build_tgsi_intrinsic;
-       bld_base->op_actions[TGSI_OPCODE_SNE].intr_name = "llvm.AMDGPU.sne";
-       bld_base->op_actions[TGSI_OPCODE_SGT].emit = lp_build_tgsi_intrinsic;
-       bld_base->op_actions[TGSI_OPCODE_SGT].intr_name = "llvm.AMDGPU.sgt";
-       bld_base->op_actions[TGSI_OPCODE_SIN].emit = lp_build_tgsi_intrinsic;
+       bld_base->op_actions[TGSI_OPCODE_SGE].emit = emit_cmp;
+       bld_base->op_actions[TGSI_OPCODE_SEQ].emit = emit_cmp;
+       bld_base->op_actions[TGSI_OPCODE_SLE].emit = emit_cmp;
+       bld_base->op_actions[TGSI_OPCODE_SLT].emit = emit_cmp;
+       bld_base->op_actions[TGSI_OPCODE_SNE].emit = emit_cmp;
+       bld_base->op_actions[TGSI_OPCODE_SGT].emit = emit_cmp;
+       bld_base->op_actions[TGSI_OPCODE_SIN].emit = build_tgsi_intrinsic_nomem;
        bld_base->op_actions[TGSI_OPCODE_SIN].intr_name = "llvm.AMDGPU.sin";
        bld_base->op_actions[TGSI_OPCODE_TEX].fetch_args = tex_fetch_args;
        bld_base->op_actions[TGSI_OPCODE_TEX].intr_name = "llvm.AMDGPU.tex";
        bld_base->op_actions[TGSI_OPCODE_TXB].fetch_args = tex_fetch_args;
        bld_base->op_actions[TGSI_OPCODE_TXB].intr_name = "llvm.AMDGPU.txb";
-       bld_base->op_actions[TGSI_OPCODE_TXD].fetch_args = tex_fetch_args;
+       bld_base->op_actions[TGSI_OPCODE_TXD].fetch_args = txd_fetch_args;
        bld_base->op_actions[TGSI_OPCODE_TXD].intr_name = "llvm.AMDGPU.txd";
        bld_base->op_actions[TGSI_OPCODE_TXL].fetch_args = tex_fetch_args;
        bld_base->op_actions[TGSI_OPCODE_TXL].intr_name = "llvm.AMDGPU.txl";
+       bld_base->op_actions[TGSI_OPCODE_TXP].fetch_args = txp_fetch_args;
        bld_base->op_actions[TGSI_OPCODE_TXP].intr_name = "llvm.AMDGPU.tex";
-       bld_base->op_actions[TGSI_OPCODE_TRUNC].emit = lp_build_tgsi_intrinsic;
+       bld_base->op_actions[TGSI_OPCODE_TRUNC].emit = build_tgsi_intrinsic_nomem;
        bld_base->op_actions[TGSI_OPCODE_TRUNC].intr_name = "llvm.AMDGPU.trunc";
 
-       bld_base->rsq_action.emit = lp_build_tgsi_intrinsic;
+       bld_base->rsq_action.emit = build_tgsi_intrinsic_nomem;
        bld_base->rsq_action.intr_name = "llvm.AMDGPU.rsq";
 }