[llvm] r201291 - [DAG] Fix the recognition of opaque constants in the SelectionDAGBuilder.

Juergen Ributzka juergen at apple.com
Wed Feb 12 20:19:26 PST 2014


Author: ributzka
Date: Wed Feb 12 22:19:26 2014
New Revision: 201291

URL: http://llvm.org/viewvc/llvm-project?rev=201291&view=rev
Log:
[DAG] Fix the recognition of opaque constants in the SelectionDAGBuilder.

This fix checks the original LLVM IR node to identify opaque constants by
looking for the bitcast-constant pattern. Originally we looked at the generated
SDNode, but this might lead to incorrect results. The SDNode could have been
generated by an constant expression that was folded to a constant.

This fixes <rdar://problem/16050719>

Added:
    llvm/trunk/test/CodeGen/X86/opaque-constant-asm.ll
Modified:
    llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp

Modified: llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp?rev=201291&r1=201290&r2=201291&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp (original)
+++ llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp Wed Feb 12 22:19:26 2014
@@ -2996,9 +2996,13 @@ void SelectionDAGBuilder::visitBitCast(c
   if (DestVT != N.getValueType())
     setValue(&I, DAG.getNode(ISD::BITCAST, getCurSDLoc(),
                              DestVT, N)); // convert types.
-  else if(ConstantSDNode *C = dyn_cast<ConstantSDNode>(N))
-    setValue(&I, DAG.getConstant(C->getAPIntValue(), C->getValueType(0),
-                                 /*isTarget=*/false, /*isOpaque*/true));
+  // Check if the original LLVM IR Operand was a ConstantInt, because getValue()
+  // might fold any kind of constant expression to an integer constant and that
+  // is not what we are looking for. Only regcognize a bitcast of a genuine
+  // constant integer as an opaque constant.
+  else if(ConstantInt *C = dyn_cast<ConstantInt>(I.getOperand(0)))
+    setValue(&I, DAG.getConstant(C->getValue(), DestVT, /*isTarget=*/false,
+                                 /*isOpaque*/true));
   else
     setValue(&I, N);            // noop cast.
 }

Added: llvm/trunk/test/CodeGen/X86/opaque-constant-asm.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/opaque-constant-asm.ll?rev=201291&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/X86/opaque-constant-asm.ll (added)
+++ llvm/trunk/test/CodeGen/X86/opaque-constant-asm.ll Wed Feb 12 22:19:26 2014
@@ -0,0 +1,13 @@
+; RUN: llc < %s -mtriple=x86_64-apple-darwin | FileCheck %s
+; This tests makes sure that we not mistake the bitcast inside the asm statement
+; as an opaque constant. If we do, then the compilation will simply fail.
+
+%struct2 = type <{ i32, i32, i32, i32 }>
+%union.anon = type { [2 x i64], [4 x i32] }
+%struct1 = type { i32, %union.anon }
+
+define void @test() {
+; CHECK: #ASM $16
+  call void asm sideeffect "#ASM $0", "n"(i32 ptrtoint (i32* getelementptr inbounds (%struct2* bitcast (%union.anon* getelementptr inbounds (%struct1* null, i32 0, i32 1) to %struct2*), i32 0, i32 2) to i32))
+  ret void
+}





More information about the llvm-commits mailing list