Fix some places where we were assuming that memory type had been legalized
authorEric Christopher <echristo@gmail.com>
Wed, 25 Nov 2015 09:11:53 +0000 (09:11 +0000)
committerEric Christopher <echristo@gmail.com>
Wed, 25 Nov 2015 09:11:53 +0000 (09:11 +0000)
to a simple type when lowering a truncating store of a vector type. In this
case for an EVT we'll return Expand as we should in all of the cases anyhow.

The testcase triggered at the one in VectorLegalizer::LegalizeOp, inspection
found the rest.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@254061 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/CodeGen/BasicTTIImpl.h
lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
lib/CodeGen/SelectionDAG/LegalizeVectorOps.cpp
test/CodeGen/X86/trunc-store.ll [new file with mode: 0644]

index 6eb4bb26c9b8da78d295553249a23b2b6d37d587..e2245e9984b877e1eac33df70218c6fa9c080569 100644 (file)
@@ -496,13 +496,11 @@ public:
       // itself. Unless the corresponding extending load or truncating store is
       // legal, then this will scalarize.
       TargetLowering::LegalizeAction LA = TargetLowering::Expand;
       // itself. Unless the corresponding extending load or truncating store is
       // legal, then this will scalarize.
       TargetLowering::LegalizeAction LA = TargetLowering::Expand;
-      EVT MemVT = getTLI()->getValueType(DL, Src, true);
-      if (MemVT.isSimple() && MemVT != MVT::Other) {
-        if (Opcode == Instruction::Store)
-          LA = getTLI()->getTruncStoreAction(LT.second, MemVT.getSimpleVT());
-        else
-          LA = getTLI()->getLoadExtAction(ISD::EXTLOAD, LT.second, MemVT);
-      }
+      EVT MemVT = getTLI()->getValueType(DL, Src);
+      if (Opcode == Instruction::Store)
+        LA = getTLI()->getTruncStoreAction(LT.second, MemVT);
+      else
+        LA = getTLI()->getLoadExtAction(ISD::EXTLOAD, LT.second, MemVT);
 
       if (LA != TargetLowering::Legal && LA != TargetLowering::Custom) {
         // This is a vector load/store for some illegal type that is scalarized.
 
       if (LA != TargetLowering::Legal && LA != TargetLowering::Custom) {
         // This is a vector load/store for some illegal type that is scalarized.
index b465ffb5d1be10bc8360d43db18a2e3242ffeeb5..c5810525f3c70c061c4cc822e9fb933970fe150d 100644 (file)
@@ -844,8 +844,7 @@ void SelectionDAGLegalize::LegalizeStoreOps(SDNode *Node) {
         SDValue Result = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, Lo, Hi);
         ReplaceNode(SDValue(Node, 0), Result);
       } else {
         SDValue Result = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, Lo, Hi);
         ReplaceNode(SDValue(Node, 0), Result);
       } else {
-        switch (TLI.getTruncStoreAction(ST->getValue().getSimpleValueType(),
-                                        StVT.getSimpleVT())) {
+        switch (TLI.getTruncStoreAction(ST->getValue().getValueType(), StVT)) {
         default: llvm_unreachable("This action is not supported yet!");
         case TargetLowering::Legal: {
           EVT MemVT = ST->getMemoryVT();
         default: llvm_unreachable("This action is not supported yet!");
         case TargetLowering::Legal: {
           EVT MemVT = ST->getMemoryVT();
index f98b801e0ae72a1d6d821a02643e04131c0ddef3..1fb7b160a67177902e006b29cc96d9aa7b72b62a 100644 (file)
@@ -231,7 +231,7 @@ SDValue VectorLegalizer::LegalizeOp(SDValue Op) {
     EVT StVT = ST->getMemoryVT();
     MVT ValVT = ST->getValue().getSimpleValueType();
     if (StVT.isVector() && ST->isTruncatingStore())
     EVT StVT = ST->getMemoryVT();
     MVT ValVT = ST->getValue().getSimpleValueType();
     if (StVT.isVector() && ST->isTruncatingStore())
-      switch (TLI.getTruncStoreAction(ValVT, StVT.getSimpleVT())) {
+      switch (TLI.getTruncStoreAction(ValVT, StVT)) {
       default: llvm_unreachable("This action is not supported yet!");
       case TargetLowering::Legal:
         return TranslateLegalizeResults(Op, Result);
       default: llvm_unreachable("This action is not supported yet!");
       case TargetLowering::Legal:
         return TranslateLegalizeResults(Op, Result);
diff --git a/test/CodeGen/X86/trunc-store.ll b/test/CodeGen/X86/trunc-store.ll
new file mode 100644 (file)
index 0000000..9b14534
--- /dev/null
@@ -0,0 +1,49 @@
+; RUN: llc < %s -march=x86-64 | FileCheck %s
+
+; With optimization at O2 we actually get the legalized function optimized
+; away through legalization and stack coloring, but check that we do all of
+; that here and don't crash during legalization.
+
+; Original program:
+; typedef enum { A, B, C, D } P;
+; struct { P x[2]; } a;
+
+; void fn2();
+; void fn1() {
+;   int b;
+;   unsigned c;
+;   for (;; c++) {
+;     fn2();
+;     unsigned n;
+;     for (; c; c++) {
+;       b = a.x[c] == A || a.x[c] == B || a.x[c] == D;
+;       if (b) n++;
+;     }
+;     if (n)
+;      for (;;)
+;        ;
+;   }
+; }
+
+define void @fn1() {
+; CHECK-LABEL: fn1
+; CHECK: movb  $0, -8(%rsp)
+; CHECK: cmpq  $8, %rax
+for.cond:
+  br label %vector.body
+
+vector.body:                                      ; preds = %vector.body, %for.cond
+  %x42 = bitcast <4 x i4> zeroinitializer to i16
+  %x43 = icmp ne i16 %x42, 0
+  %x44 = select i1 %x43, i32 undef, i32 0
+  %x72 = bitcast <4 x i1> zeroinitializer to i4
+  %x73 = icmp ne i4 %x72, 0
+  %x74 = select i1 %x73, i32 %x44, i32 undef
+  %x84 = select i1 undef, i32 undef, i32 %x74
+  %x88 = icmp eq i64 undef, 8
+  br i1 %x88, label %middle.block, label %vector.body
+
+middle.block:                                     ; preds = %vector.body
+  %0 = select i1 undef, i32 undef, i32 %x84
+  ret void
+}